home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Apple IIGS SCSI Driver Shell / SCSI Driver Mgmt < prev    next >
Encoding:
Text File  |  1990-09-14  |  145.3 KB  |  6,623 lines  |  [TEXT/MPS ]

  1.  
  2. ;*******************************************************
  3. ;
  4. ;    SCSI Driver Management Routines.
  5. ;
  6. ;    Written by Matt Gulick.        Started May 16,1988
  7. ;
  8. ;    Copyright Apple Computer, Inc. 1988,89
  9. ;
  10. ;*******************************************************
  11.  
  12. ;*******************************************************
  13. ;
  14. ;    This file contains the subroutines needed by the
  15. ;    SCSI Driver for things such as Getting RAM, Building
  16. ;    data areas, calling outside routines for DIB
  17. ;    management, as well as other generic routines that
  18. ;    are used to make life easier for the driver.  Also
  19. ;    included in this file is the record definition for
  20. ;    the DIB structure including all it's extensions.
  21. ;
  22. ;*******************************************************
  23.  
  24. ;*******************************************************
  25. ;
  26. ;    Revision History:
  27. ;
  28. ;*******************************************************
  29.  
  30. ;    May 16, 1988    File started.
  31. ;    May 17,    1988    DIB Record defined.
  32. ;    June 6,    1988    Main Driver Written.
  33. ;    Jun 20,    1988    Update Input/Output Data in Comments
  34. ;    Apr    14,    1989    Added Conditional Logic to remove
  35. ;                    block routines from character device
  36. ;                    assemblies.
  37.  
  38.                 STRING        PASCAL
  39.                 BLANKS        OFF
  40.                 PAGESIZE    70
  41.                 PRINT        NOGEN
  42.                 PRINT        NOMDIR
  43.                 MACHINE        M65816
  44.  
  45.                 IMPORT        master_uid
  46.                 IMPORT        scsi_uid
  47.                 IMPORT        scsi_mgrnum
  48.                 IMPORT        rout2_s_disp
  49.                 IMPORT        hndl_offset
  50.                 IMPORT        buff_len
  51.                 IMPORT        page_cnt
  52.                 IMPORT        dpi_overide
  53.                 IMPORT        call_type
  54.                 IMPORT        main_drvr
  55.                 IMPORT        internal
  56. ;                IMPORT        disk_switch
  57.                 IMPORT        ram_page_cnt
  58.                 IMPORT        internal_buff
  59.                 IMPORT        default_dib
  60.                 IMPORT        first_time
  61.                 IMPORT        only_one
  62.                 IMPORT        part_cnt
  63.                 IMPORT        t_dvc_blocks
  64.                 IMPORT        f_partition
  65.                 IMPORT        part_num
  66.                 IMPORT        vPart_cnt
  67.                 IMPORT        rebuild
  68.                 IMPORT        trash_it
  69.                 IMPORT        direct_page
  70.                 IMPORT        exit_dpage
  71.                 IMPORT        gsos_dpage
  72.                 IMPORT        saved_zp
  73.                 IMPORT        valid
  74.                 IMPORT        dvc_ram
  75.                 IMPORT        sense_data
  76.                 IMPORT        dvc_count
  77.                 IMPORT        result
  78.                 IMPORT        divend
  79.                 IMPORT        divsor
  80.                 IMPORT        max_blk_cnt
  81.                 IMPORT        tot_dib_cnt
  82.                 IMPORT        dib_data_struct
  83.                 IMPORT        main_caller
  84.                 IMPORT        curr_hndl
  85.                 IMPORT        new_dib
  86.                 IMPORT        scratch0
  87.                 IMPORT        scratch1
  88.                 IMPORT        scratch2
  89.                 IMPORT        scratch3
  90.                 IMPORT        killer_blk
  91.                 IMPORT        auto_sense_data
  92.                 IMPORT        temp_acc
  93.                 IMPORT        pdi_flag
  94.                 IMPORT        new_list
  95.                 IMPORT        new_dib_cnt
  96.                 IMPORT        new_dib_list
  97.                 IMPORT        real_unit            ;*************************
  98.  
  99.                 IMPORT        m_blk_size
  100.                 IMPORT        m_blk_cnt
  101.                 IMPORT        m_rslt
  102.  
  103.                 ENTRY        zero_mem
  104.                 ENTRY        get_space
  105.  
  106.                 ENTRY        make_dib
  107.                 ENTRY        find_empty
  108.                 ENTRY        chk_ram
  109.  
  110.                 ENTRY        rebld_dibs
  111.                 ENTRY        dibicise_new_ram
  112.                 ENTRY        dibicise_new_dib
  113.                 ENTRY        set_link_ptrs
  114.                 ENTRY        major_update
  115.                 ENTRY        minor_update
  116.  
  117.                 ENTRY        fix_unit_1
  118.                 ENTRY        add_dib_ptr
  119.                 ENTRY        do_post_install
  120.  
  121.                 ENTRY        read_pm_blk
  122.                 ENTRY        pm_blk_num
  123.                 ENTRY        chk_map
  124.                 ENTRY        no_partition
  125.                 ENTRY        check_map_entry
  126.  
  127.                 ENTRY        c_strt_buffer
  128.                 ENTRY        c_strt_rqst_cnt
  129.                 ENTRY        c_strt_blk_num
  130.                 ENTRY        cache_valid
  131.                 ENTRY        put_in_cache
  132.                 ENTRY        get_from_cache
  133.  
  134.                 ENTRY        test_unit_rdy
  135.                 ENTRY        read_capacity
  136.  
  137.                 ENTRY        start_unit
  138.                 ENTRY        stop_unit
  139.                 ENTRY        set_512_mode
  140.  
  141.                 ENTRY        notify_me
  142.  
  143.                 ENTRY        set_disk_sw
  144.                 ENTRY        trash_volume
  145.                 ENTRY        save_dp
  146.                 ENTRY        restore_dp
  147.                 ENTRY        set_our_dp
  148.                 ENTRY        check_532_rw
  149.                 ENTRY        munge_532
  150.                 ENTRY        divide
  151.  
  152.                 PRINT        OFF
  153.  
  154.                 INCLUDE        'scsihd.equates'
  155.                 INCLUDE        'M16.MEMORY'
  156.                 INCLUDE        'M16.UTIL'
  157.                 INCLUDE        'M16.MISCTOOL'
  158.                 PRINT        ON
  159.  
  160.                 EJECT
  161. ;____Mem_Manager_____
  162. ;*******************************************************
  163. ;
  164. ;    This routine is used to Get a User ID from the
  165. ;    memory manager for the SCSI Driver.  This is
  166. ;    required to get a userID for access reference.
  167. ;
  168. ;    Inputs:        None.
  169. ;
  170. ;    Outputs:    SCSID_uID    =    userID.
  171. ;                Registers    =    Scrambled
  172. ;
  173. ;    Errors:        $0207    iderr    Invalid userID.
  174. ;
  175. ;*******************************************************
  176.  
  177.             EXPORT    get_mm_id
  178. get_mm_id    PROC
  179.                                 ;
  180.                                 ; Get userID.
  181.                                 ;
  182.             pushword    #$0000
  183.  
  184.             pushword    #scsi_duid
  185.  
  186.             _GetNewID
  187.             pla
  188.             sta        |master_uid
  189.             sta        |scsi_uid
  190. @rts        rts
  191.             
  192.             ENDP
  193.  
  194.             EJECT
  195.  
  196. ;*******************************************************
  197. ;
  198. ;    This routine is used to get the SCSI Manager Number
  199. ;    from the Supervisory Dispatcher at startup time.
  200. ;
  201. ;    Inputs:        None.
  202. ;
  203. ;    Outputs:    scsi_mgrnum        =    SCSI Manager Number
  204. ;                All Registers    =    scrambled
  205. ;
  206. ;    Errors:        None.
  207. ;
  208. ;*******************************************************
  209.  
  210.             EXPORT    get_scsimgr
  211. get_scsimgr    PROC
  212.                                 ;
  213.                                 ; Get userID.
  214.                                 ;
  215.             lda        #$0000        ; Supervisor Driver Number (Unknown at this time)
  216.             tax                    ; Supervisor Call Number ($0000)
  217.             ldy        #$0002        ; Spervisor ID for SCSI Manager ($0002)
  218.             jsr        |rout2_s_disp
  219.             stx        |scsi_mgrnum    ; Preserve SCSI Driver Number for later use.
  220.             rts
  221.             
  222.             ENDP
  223.  
  224.             EJECT
  225.  
  226. ;*******************************************************
  227. ;
  228. ;    'zero_mem'
  229. ;
  230. ;    This routine will fill a section of memory with
  231. ;    $00s.
  232. ;
  233. ;    Inputs:        Acc            =    Buffer Size
  234. ;                X            =    Low Byte of new RAM Address
  235. ;                Y            =    High Byte of new RAM Address
  236. ;
  237. ;    Outputs:    scsi_zp0    =    Long Pointer to new RAM
  238. ;                                Address
  239. ;                Acc            =    Scrambled
  240. ;
  241. ;    Errors:        None.
  242. ;
  243. ;*******************************************************
  244.  
  245.                 EXPORT    zero_mem
  246. zero_mem        PROC
  247.                                         ;
  248.                                         ; Save the buffer size.
  249.                                         ;
  250.                 sta        @buff_size
  251.                                         ;
  252.                                         ; Setup MOVE_INFO call for a
  253.                                         ; non-incrementing source and an
  254.                                         ; incrementing destination.
  255.                                         ;
  256.                 pushlong    #null_buff    ;Source
  257.                 phy                        ;Destination High Word
  258.                 phx                        ;Destination Low Word
  259.                                         ;
  260.                                         ; Restore buffer size.  If = 0 then
  261.                                         ; we are to do an entire bank or at
  262.                                         ; least 64k bytes.  This may cross
  263.                                         ; banks.
  264.                                         ;
  265.                 lda        @buff_size
  266.                 beq        @do_64k
  267.                 pea        $0000
  268.                 pha
  269.                 bra        @move_type
  270.  
  271. @do_64k            pea        $0001
  272.                 pea        $0000
  273.  
  274. @move_type        pea        #move_scon_dinc
  275.                 jsl        move_info
  276.  
  277. @rts            rts
  278.                                         ;
  279.                                         ; Data for this call
  280.                                         ;
  281. @buff_size        dc.w    null
  282. null_buff        dc.w    null
  283.  
  284.                 ENDP
  285.  
  286.                 EJECT
  287.  
  288. ;*******************************************************
  289. ;
  290. ;    This routine is used to request a section of RAM from
  291. ;    the memory manager for use by the driver.  This
  292. ;    routine allocates space for as requested by the byte
  293. ;    count in the Acc.
  294. ;
  295. ;    Inputs:        Acc            =    Number of bytes requested.
  296. ;                                0 = 1 bank
  297. ;
  298. ;                Y            =    Offset to where the Handle
  299. ;                                should be stored within
  300. ;                                the allocated structure.
  301. ;
  302. ;    Outputs:    X            =    Low Word of new RAM Address
  303. ;                Y            =    High Word of new RAM Address
  304. ;                scsi_zp0    =    Long Pointer to new RAM
  305. ;                                Address
  306. ;                Acc            =    Scrambled
  307. ;
  308. ;    Errors:        Not enough memory if carry set.
  309. ;
  310. ;*******************************************************
  311.  
  312.                 EXPORT    get_space
  313. get_space        PROC
  314.                                         ;
  315.                                         ; Request Acc bytes of RAM from
  316.                                         ; Memory Manager.
  317.                                         ;
  318.                 sty        |hndl_offset
  319.  
  320.                 pushlong #00000000        ;Space for result handle
  321.  
  322.                 cmp        $0000            ;Is it Null?
  323.                 beq        @null            ;Yes. Request 1 bank
  324.  
  325.                 pushword #0000            ;Size in bytes of requested memory.
  326.                 bra        @stuff_a
  327.  
  328. @null            pushword #0001            ;Request 1 bank
  329.  
  330. @stuff_a        sta        |buff_len
  331.                 pha
  332.             
  333.                 pushword scsi_uid        ;Our User ID
  334.             
  335.                                         ;Attributes of requested mem.
  336.                 pea        attrfixed++\
  337.                         attrnocross++\
  338.                         attrnospec++\
  339.                         attrpage
  340.  
  341.                 pushlong #00000000        ;Location Pointer.  Unused.
  342.  
  343.                 _newhandle
  344.  
  345.                 plx                        ; Get handle
  346.                 ply
  347.  
  348.                 bcs        @rts            ; Exit if an error.
  349.  
  350.                                         ;
  351.                                         ; Save Handle for later
  352.                                         ;
  353.                 phy
  354.                 phx
  355.                                         ;
  356.                                         ; DEREF the Handle and get a
  357.                                         ; pointer for the new RAM.
  358.                                         ;
  359.                 stx        <scsi_zp0
  360.                 sty        <scsi_zp0+2
  361.                 ldy        #$0002
  362.                 lda        [scsi_zp0]
  363.                 tax
  364.                 lda        [scsi_zp0],y
  365.                 tay
  366.                                         ;
  367.                                         ; Stuff pointer for indirect access.
  368.                                         ;
  369.                 stx        <scsi_zp0
  370.                 sty        <scsi_zp0+2
  371.                                         ;
  372.                                         ; Call routine to zero out the
  373.                                         ; new memory
  374.                                         ;
  375.                 lda        |buff_len
  376.                 jsr        zero_mem
  377.                                         ;
  378.                                         ; Stuff Handle in RAM. Low byte first
  379.                                         ;
  380.                 ldy        |hndl_offset
  381.                 pullword [scsi_zp0],y
  382.                 iny
  383.                 iny
  384.                 pullword [scsi_zp0],y
  385.                                         ;
  386.                                         ; Restore X and Y to pointer status
  387.                                         ;
  388.                 ldx        <scsi_zp0
  389.                 ldy        <scsi_zp0+2
  390.                                         ;
  391.                                         ; Clean Exit.
  392.                                         ;
  393.                 clc
  394. @rts            rts
  395.  
  396.                 ENDP
  397.  
  398.                 EJECT
  399.  
  400. ;*******************************************************
  401. ;
  402. ;    This routine is used to request a section of RAM from
  403. ;    the memory manager for use by the driver.  This
  404. ;    routine allocates space for the get_devices call to
  405. ;    the SCSI Manager.
  406. ;
  407. ;    Inputs:        None.
  408. ;
  409. ;    Outputs:    dvc_list    =    Long Pointer to device List
  410. ;                next_dib    =    Long Pointer to First DIB
  411. ;                first_dib    =    Long Pointer to the beginning
  412. ;                                of the RAM Allocated for the
  413. ;                                new DIBs.
  414. ;                Acc            =    Scrambled
  415. ;
  416. ;    Errors:        Not enough memory if carry set.
  417. ;
  418. ;*******************************************************
  419.  
  420.                 EXPORT    get_dvc_ram
  421. get_dvc_ram        PROC
  422.                                             ;
  423.                                             ; Request the maximum device list
  424.                                             ; size bytes of RAM from GS/OS
  425.                                             ; System Service calls.
  426.                                             ;
  427.                 lda        #max_gdvc_buf+4        ; Allocate space for list.
  428.                 ldy        #$0000
  429.  
  430.                 ldx        |direct_page        ;If this is the first time, then
  431.                 bne        @use_ours
  432.                 phx                            ;we don't want a DP setting of
  433.                                             ;NULL
  434.                                             ;
  435.                                             ; Save away GS/OS Direct Page values
  436.                                             ; until we have our own direct Page.
  437.                                             ;
  438.                 jsr        save_dp
  439.  
  440.                 lda        #max_gdvc_buf+4        ; Allocate space for list.
  441.                 ldy        #$0000
  442.  
  443.                 ldx        |gsos_dpage
  444.                 stx        |direct_page
  445.  
  446.                 jsr        |get_space
  447.  
  448.                 pla                            ;Restore our settings preserving X & Y
  449.                 sta        |direct_page
  450.                 sta        |exit_dpage
  451.                 bra        @over_use_ours
  452.  
  453. @use_ours        jsr        |get_space
  454.                                             ;
  455.                                             ; Store newly allocated buffer
  456.                                             ; pointer into the parm list for
  457.                                             ; the get devices call.  Account
  458.                                             ; for the first 4 bytes that
  459.                                             ; contain the handle associated
  460.                                             ; with this memory segment.
  461.                                             ;
  462. @over_use_ours    bcs        @rts_long
  463.                 clc
  464.                 txa
  465.                 sta        |dvc_ram
  466.                 adc        #$0004
  467.                 sta        |dvc_buff
  468.                 sta        <dvc_list
  469.                 tya
  470.                 sta        |dvc_ram+2
  471.                 adc        #$0000
  472.                 sta        |dvc_buff+2
  473.                 sta        <dvc_list+2
  474.                                             ;
  475.                                             ; Setup Pointer to our parm list
  476.                                             ; in GS/OS Direct Page.
  477.                                             ;
  478.                 ldx        |gsos_dpage
  479.                 lda        #get_dev_lst
  480.                 sta        >smgr_pl_ptr,x
  481.                 lda        #^get_dev_lst
  482.                 sta        >smgr_pl_ptr+2,x
  483.                                             ;
  484.                                             ; Load registers with their
  485.                                             ; required values.
  486.                                             ;
  487.                 lda        |scsi_mgrnum
  488.                 ldx        #cmd_get_dvc
  489.                 jsr        |rout2_s_disp
  490. @rts_long        bcs        @rts
  491.                                             ;
  492.                                             ; Restore our direct page Device List
  493.                                             ;
  494.                 lda        |dvc_buff
  495.                 sta        <dvc_list
  496.                 lda        |dvc_buff+2
  497.                 sta        <dvc_list+2
  498.                                             ;
  499.                                             ; First word in [dvc_list}] contains
  500.                                             ; the address of a 1 page area that
  501.                                             ; we will be using for our direct
  502.                                             ; page.  Get it and move the
  503.                                             ; 'dvc_list' pointer to our direct
  504.                                             ; page area, but only if we have not
  505.                                             ; yet done it.
  506.                                             ;
  507.                 lda        |direct_page
  508.                 bne        @we_did_it            ;It's already been done.
  509.  
  510.                 lda        [dvc_list]
  511.                 tax
  512.                 lda        <dvc_list
  513.                 sta        >dvc_list,x
  514.                 lda        <dvc_list+2
  515.                 sta        >dvc_list+2,x
  516.                 txa
  517.                 sta        |direct_page
  518.                 sta        |exit_dpage
  519.                                             ;
  520.                                             ; Set our Direct Page with the first
  521.                                             ; 'x' Bytes equal to the GS/OS DP
  522.                                             ; settings.
  523.                                             ;
  524.                                             ;
  525.                 clc                            ; Calculate Source Address of GS/OS
  526.                 tdc                            ; Direct Page that we want.
  527.                 sta        |gsos_dpage            ; Preserving GS/OS DP for later use.
  528.                 adc        #dev_num
  529.                 pea        $0000
  530.                 pha
  531.                                             ;
  532.                 clc                            ; Calculate Destination Address of
  533.                 lda        |direct_page        ; our Direct Page that we want.
  534.                 adc        #dev_num
  535.                 pea        $0000
  536.                 pha
  537.                 
  538.                 pushlong    #dib_ptr+4        ;Length of the move
  539.                 
  540.                 pushword    #move_sinc_dinc
  541.  
  542.                 jsl        move_info            ;Move the data
  543.                                             ;
  544.                                             ; Restore the Direct Page that we
  545.                                             ; borrowed until this was done.
  546.                                             ;
  547.                 jsr        restore_dp
  548.                                             ;
  549.                                             ; Set our Direct Page.
  550.                                             ;
  551.                 lda        |direct_page
  552.                 tcd
  553.                                             ;
  554.                                             ; Check for zero Devices.
  555.                                             ;
  556. @we_did_it        ldy        #$0002
  557.                 lda        [dvc_list],y
  558.                 beq        @no_devices
  559.                                             ;
  560.                                             ; Ensure that device count is
  561.                                             ; in range.
  562.                                             ;
  563.                 cmp        #$0100+1            ;No more than 256 devices
  564.                 blt        @count_ok
  565.                 lda        #max_dvc_cnt        ;Max Count
  566. @count_ok        sta        |dvc_count
  567.                 jsr        |make_dib
  568.                 stx        <next_dib
  569.                 stx        <first_dib
  570.                 sty        <next_dib+2
  571.                 sty        <first_dib+2
  572.  
  573.                 lda        #no_error
  574.                 clc
  575.                                             ;
  576.                                             ; Restore the Direct Page that we
  577.                                             ; borrowed until this was done.
  578.                                             ;
  579. @rts            pha
  580.                 php
  581.                 jsr        restore_dp
  582.                 plp
  583.                 pla
  584.                 rts
  585.                                             ;
  586.                                             ; No Devices Error.
  587.                                             ;
  588.                                             ; Restore the Direct Page that we
  589.                                             ; borrowed until this was done.
  590.                                             ;
  591. @no_devices        jsr        restore_dp
  592.                 lda        #drvr_no_dev
  593.                 sec
  594.                 rts
  595.  
  596. get_dev_lst        dc.w    scsi_dtype
  597.                 dc.l    notify_me
  598. dvc_buff        dc.l    null
  599.  
  600.                 ENDP
  601.  
  602.                 EJECT
  603.  
  604. ;*******************************************************
  605. ;
  606. ;    This routine is the inverse of the above routine.
  607. ;    It calls the memory manager to deallocate the space
  608. ;    we used to request the device list from the SCSI
  609. ;    manager.
  610. ;
  611. ;    Inputs:        X            =    Low byte of Buffer pointer
  612. ;                Y            =    High byte of Buffer pointer
  613. ;
  614. ;    Outputs:    All Regs    =    Scrambled
  615. ;
  616. ;    Errors:        Not enough memory if carry set.
  617. ;
  618. ;*******************************************************
  619.  
  620.                 EXPORT    fre_dvc_ram
  621. fre_dvc_ram        PROC
  622.                                         ;
  623.                                         ; Remove the device list from
  624.                                         ; active use and free the mem.
  625.                                         ;
  626.                                         ; Stuff pointer for indirect access.
  627.                                         ;
  628.                 lda        |dvc_ram
  629.                 sta        <scsi_zp0
  630.                 lda        |dvc_ram+2
  631.                 sta        <scsi_zp0+2
  632.  
  633.                 ldy        #$0002            ;High byte first on stack
  634.                 pushword [scsi_zp0],y
  635.                 pushword [scsi_zp0]
  636.  
  637.                 _disposehandle                    
  638.  
  639.                 rts
  640.  
  641.                 ENDP
  642.  
  643.                 EJECT
  644.  
  645. ;____DIB_Mem_Mgr_____
  646. ;*******************************************************
  647. ;
  648. ;    This routine is used to request a section of RAM from
  649. ;    the memory manager for use by the driver.  This
  650. ;    routine allocates space for 1 DIB.
  651. ;
  652. ;    Inputs:        Acc            =    $00xx = DIB Count.
  653. ;                                Null = $0100
  654. ;
  655. ;    Outputs:    X            =    Low Byte of new RAM Address
  656. ;                Y            =    High Byte of new RAM Address
  657. ;                scsi_zp0    =    Long Pointer to new RAM
  658. ;                                Address
  659. ;                Acc            =    Scrambled
  660. ;
  661. ;    Errors:        Not enough memory if carry set.
  662. ;
  663. ;*******************************************************
  664.  
  665.                 EXPORT    make_dib
  666. make_dib        PROC
  667.                                         ;
  668.                                         ; Request $100 bytes of RAM for
  669.                                         ; each DIB from GS/OS System
  670.                                         ; Service calls.
  671.                                         ;
  672.                 and        #$00ff
  673.                 sta        |ram_page_cnt
  674.                 xba                        ;Cheap multiply by $0100
  675.                 ldy        #dib.handle        ;Offset to where we want the handle
  676.                 jsr        |get_space        ;Allocate space for DIBs.
  677.                 bcc        @rts
  678.                 stz        |ram_page_cnt
  679. @rts            rts
  680.             
  681.                 ENDP
  682.  
  683.                 EJECT
  684.  
  685. ;*******************************************************
  686. ;
  687. ;    This routine is called via a 'jsl' and returns the
  688. ;    page number of the caller in X and Y with X being
  689. ;    the low byte.  This is intended for use by the
  690. ;    completion routines in the DIB as a tool to find
  691. ;    the DIB's starting location in memory
  692. ;
  693. ;    Inputs:        None.
  694. ;
  695. ;    Outputs:    X            =    Low byte of callers page
  696. ;                Y            =    High byte of callers page
  697. ;                Acc            =    Scrambled
  698. ;
  699. ;    Errors:        None.
  700. ;
  701. ;*******************************************************
  702.  
  703.                 EXPORT    g_dib_ptr
  704. g_dib_ptr        PROC
  705.                                     ;
  706.                                     ; Get the callers return
  707.                                     ; address from the stack,
  708.                                     ; strip down to a page number,
  709.                                     ; transfer to X and Y and
  710.                                     ; return to caller via an 'rtl'
  711.                                     ;
  712.                 lda        <1,s
  713.                 sec
  714.                 sbc        #dib.complet+3-dib.linkptr
  715.                 tax
  716.                 lda        <3,s
  717.                 and        #$00ff
  718.                 tay
  719.                 rtl
  720.  
  721.                 ENDP
  722.  
  723.                 EJECT
  724.  
  725. ;*******************************************************
  726. ;
  727. ;    'ADD_DIB_RAM'
  728. ;
  729. ;    This routine searches for the last DIB for this
  730. ;    driver, allocates enough ram for 4 additional DIBs
  731. ;    and links them in.
  732. ;
  733. ;    Inputs:        dib_ptr            =    Last DIB in Device link
  734. ;                add_dib_here    =    Where the new DIB is to be built
  735. ;                Acc                =    Unspecified
  736. ;                Y register        =    Unspecified
  737. ;                X register        =    Unspecified
  738. ;                P register        =    0=M=X=e
  739. ;                Direct Page        =    Ours
  740. ;                Data Bank        =    Ours
  741. ;
  742. ;    Outputs:    Acc                =    Unspecified
  743. ;                Y register        =    Unspecified
  744. ;                X register        =    Unspecified
  745. ;                P register        =    0=M=X=e
  746. ;                Direct Page        =    Ours
  747. ;                Data Bank        =    Ours
  748. ;
  749. ;    Errors:        Carry set if not enough memory
  750. ;
  751. ;*******************************************************
  752.  
  753.                 EXPORT    add_dib_ram
  754. add_dib_ram        PROC
  755.                                             ;
  756.                                             ; 'ADD_DIB_HERE' Pointer now points
  757.                                             ; to the last DIB currently allocated
  758.                                             ; and preserve location of last DIB.
  759.                                             ;
  760.                 lda        <add_dib_here
  761.                 sta        <last_dib
  762.                 pha                            ;Save and later restore
  763.                 lda        <add_dib_here+2
  764.                 sta        <last_dib+2
  765.                 pha                            ;Save and later restore
  766.                                             ;
  767.                                             ; Get some RAM for a few more DIBs..
  768.                                             ;
  769.                 lda        #dibs_2_make
  770.                 jsr        make_dib
  771.                 bcc        @over_0
  772.                                             ;
  773.                                             ; Got an Error. Fix the Stack and Exit.
  774.                                             ;
  775.                 tax
  776.  
  777.                 pla                            ;Saved, and now restore
  778.                 sta        <last_dib+2
  779.                 pla                            ;Saved, and now restore
  780.                 sta        <last_dib
  781.  
  782.                 txa
  783.  
  784.                 rts
  785.                                             ;
  786.                                             ; Do First link
  787.                                             ;
  788. @over_0            sty        <first_dib+2
  789.                 stx        <first_dib
  790.                                             ;
  791.                                             ; Dibicise first new DIB in the new
  792.                                             ; Memory.
  793.                                             ;
  794.                 sec                            ;Don't do the links.
  795.                 jsr        dibicise_new_ram
  796.                                             ;
  797.                                             ; Do the Head and Forward links also.
  798.                                             ;
  799.                 lda        #null
  800.                 ldy        #dib.headlnk
  801.                 sta        [first_dib],y
  802.  
  803.                 ldy        #dib.fdvclnk
  804.                 sta        [first_dib],y
  805.  
  806.                 ldy        #dib.unitnum        ;Don't forget the unit number
  807.                 sta        [first_dib],y
  808.                                             ;
  809.                                             ; Finalise the new DIB Structure.
  810.                                             ;
  811.                 dec        |main_caller
  812.                                             ;********
  813.                                             ;******** 6/12/89  Begin fix MSG
  814.                                             ;******** rebuild flag being destroyed.
  815.                                             ;********
  816.                 lda        |rebuild            ;The state of this flag must be preserved.
  817.                 pha
  818.                 stz        |rebuild            ;Set to zero.  (Full Rebuild)
  819.  
  820.                 jsr        set_link_ptrs        ;Now we do the links.
  821.  
  822.                 pla
  823.                 sta        |rebuild            ;Restore the callers state for this flag.
  824.  
  825. ;                stz        |rebuild            ;Set to zero.  (Full Rebuild)
  826.  
  827. ;                jsr        set_link_ptrs        ;Now we do the links.
  828.                                             ;********
  829.                                             ;******** 6/12/89  End fix MSG
  830.                                             ;******** rebuild flag being destroyed.
  831.                                             ;********
  832.                                             ;
  833.                                             ; Finish the last three links.  They
  834.                                             ; live in the new memory segment.
  835.                                             ;
  836.                 lda        #dibs_2_make-1
  837.                 sta        @loop_cnt
  838.  
  839. @link_loop        clc
  840.  
  841.                 lda        <next_dib
  842.                 sta        <last_dib
  843.                 adc        #dib_size
  844.                 sta        <next_dib
  845.  
  846.                 lda        <next_dib+2
  847.                 sta        <last_dib+2
  848.                 adc        #^dib_size
  849.                 sta        <next_dib+2
  850.  
  851.                 dec        |main_caller
  852.                                             ;********
  853.                                             ;******** 6/12/89  Begin fix MSG
  854.                                             ;******** rebuild flag being destroyed.
  855.                                             ;********
  856.                 lda        |rebuild            ;The state of this flag must be preserved.
  857.                 pha
  858.                 stz        |rebuild            ;Set to zero.  (Full Rebuild)
  859.  
  860.                 jsr        dibicise_new_dib
  861.  
  862.                 pla
  863.                 sta        |rebuild            ;Restore the callers state for this flag.
  864.  
  865. ;                stz        |rebuild
  866.  
  867. ;                jsr        dibicise_new_dib
  868.                                             ;********
  869.                                             ;******** 6/12/89  End fix MSG
  870.                                             ;******** rebuild flag being destroyed.
  871.                                             ;********
  872.                 dec        @loop_cnt
  873.                 bne        @link_loop
  874.                                             ;
  875.                                             ; Clean Exit
  876.                                             ;
  877.                                             ; Reinitialise mem_dib_cnt to zero.
  878.                                             ;
  879.                 lda        #null
  880.                 ldy        #dib.mem_dib_cnt
  881.                 sta        [first_dib],y
  882.                                             ;
  883.                                             ; Wipe out last link pointer to no where.
  884.                                             ;
  885.                 sta        [next_dib]
  886.                 ldy        #dib.linkptr+2
  887.                 sta        [next_dib],y
  888.  
  889.                 pla                            ;Saved, and now restore
  890.                 sta        <last_dib+2
  891.                 pla                            ;Saved, and now restore
  892.                 sta        <last_dib
  893.  
  894.                 clc
  895.                 rts
  896.                                             ;
  897.                                             ; Data Area.
  898.                                             ;
  899. @loop_cnt        dc.w    null
  900.  
  901.                 ENDP
  902.  
  903.                 EJECT
  904.  
  905. ;*******************************************************
  906. ;
  907. ;    FIND_EMPTY
  908. ;
  909. ;    This routine serches forward from the current DIB
  910. ;    looking for an empty.  If it exits with the carry
  911. ;    clear, then one has been found.  If the carry is
  912. ;    set, then it points to the last DIB in the linked
  913. ;    list and found non empty.
  914. ;
  915. ;    Inputs:        <DIB_PTR        =    Last DIB Location
  916. ;                Acc                =    Unspecified
  917. ;                Y register        =    Unspecified
  918. ;                X register        =    Unspecified
  919. ;                P register        =    0=M=X=e
  920. ;                Direct Page        =    Ours
  921. ;                Data Bank        =    Ours
  922. ;
  923. ;    Outputs:    <ADD_DIB_HERE    =    Empty DIB if found
  924. ;                Acc                =    Unspecified
  925. ;                Y register        =    Unspecified
  926. ;                X register        =    Unspecified
  927. ;                P register        =    0=M=X=e
  928. ;                Direct Page        =    Ours
  929. ;                Data Bank        =    Ours
  930. ;
  931. ;    Errors:        Carry set if no empties were found
  932. ;
  933. ;*******************************************************
  934.  
  935.                 EXPORT    find_empty
  936. find_empty        PROC
  937.                                         ;
  938.                                         ; Are we at the last DIB? Set beginning
  939.                                         ; pointer for check.
  940.                                         ;
  941.                 lda        <dib_ptr
  942.                 sta        <last_dib
  943.                 sta        <add_dib_here
  944.                 lda        <dib_ptr+2
  945.                 sta        <last_dib+2
  946.                 sta        <add_dib_here+2
  947.                                         ;
  948.                                         ; Are we at the last DIB? (LOOP)
  949.                                         ;
  950. @fnd_empty_lup    ldy        #$0002
  951.                 lda        [add_dib_here]
  952.                 tax
  953.  
  954.                 lda        [add_dib_here],y;Should never be in Bank $00
  955.                 bne        @advance_ptr    ;No.
  956.  
  957. @sec            sec                        ;Yes. Exit
  958.                 rts
  959.                                         ;
  960.                                         ; Advance Ptr to next DIB.
  961.                                         ;
  962. @advance_ptr    sta        <add_dib_here+2
  963.                 stx        <add_dib_here
  964.                                         ;
  965.                                         ; Is it Free?
  966.                                         ;
  967.                                         ; Must have a zero Head Link Ptr,
  968.                                         ; Forward Device Link Ptr, and
  969.                                         ; DIB Device Number to be considered
  970.                                         ; free.
  971.                                         ;
  972.                 ldy        #dib.devnum
  973.                 lda        [add_dib_here],y
  974.                 bne        @fnd_empty_lup    ;No.  Check next one.
  975.  
  976.                 ldy        #dib.headlnk
  977.                 lda        [add_dib_here],y
  978.                 bne        @fnd_empty_lup    ;No.  Check next one.
  979.  
  980.                 ldy        #dib.fdvclnk
  981.                 lda        [add_dib_here],y
  982.                 bne        @fnd_empty_lup    ;No.  Check next one.
  983.                                         ;
  984.                                         ; Make the DIB Device Number non-zero
  985.                                         ; to prvent it from being selected
  986.                                         ; again before it is started up by
  987.                                         ; the operating system.
  988.                                         ;
  989.                 ldy        #dib.devnum
  990.                 lda        [add_dib_here],y
  991.                 inc        a
  992.                 sta        [add_dib_here],y
  993.  
  994.                 clc                        ;Yes. Exit
  995.                 rts
  996.  
  997.                 ENDP
  998.  
  999.                 EJECT
  1000.             
  1001. ;*******************************************************
  1002. ;
  1003. ;    'chk_ram'
  1004. ;
  1005. ;    This routine checks to see if we have any room left
  1006. ;    in this memory segment for another DIB.  If not then
  1007. ;    the memory manager is called and the new RAM is
  1008. ;    dibicised.
  1009. ;        
  1010. ;    Inputs:        Acc            =    Unspecified
  1011. ;                Carry        =    Unspecified
  1012. ;                Y register    =    Unspecified
  1013. ;                X register    =    Unspecified
  1014. ;                P register    =    0=M=X=e
  1015. ;                Direct Page    =    Ours
  1016. ;                Data Bank    =    Ours
  1017. ;
  1018. ;    Outputs:    Carry        =    1
  1019. ;                    Acc        =    Error
  1020. ;                Carry        =    0
  1021. ;                    Acc        =    ram_page_cnt
  1022. ;                            =    0    no more devices
  1023. ;                Y register    =    Unspecified
  1024. ;                X register    =    Unspecified
  1025. ;                P register    =    0=M=X=e
  1026. ;                Direct Page    =    Ours
  1027. ;                Data Bank    =    Ours
  1028. ;
  1029. ;    Errors:        None.
  1030. ;
  1031. ;*******************************************************
  1032.                                         ;
  1033.                                         ; Start of the code segment for this.
  1034.                                         ;
  1035.                 EXPORT    chk_ram
  1036. chk_ram            PROC
  1037.                                         ;
  1038.                                         ; All done with the DIB Update now
  1039.                                         ; do we have any more RAM left to
  1040.                                         ; build further DIBs?
  1041.                                         ;
  1042.                 dec        |ram_page_cnt
  1043.                 bne        @adv_ptrs        ;Yes we do.  Continue on.
  1044.  
  1045.                                         ;
  1046.                                         ; Account for 'part_cnt' being equal
  1047.                                         ; to the Actual Partition Count - 1
  1048.                                         ;
  1049.                 sec
  1050. ;                clc                        ;Bug Fix 4/3/89
  1051.  
  1052.                 lda        |dvc_count        ;No we don't.  Get the remaining device
  1053.                 adc        |part_cnt        ;count and add the remaining Part count
  1054. ;                dec        a                ;Subtract our current working device
  1055. ;                dec        a                ;Subtract our current working DIB
  1056.                 beq        @exit            ;Are we done? Yes.
  1057.                 bmi        @exit            ;Yes.
  1058.                 cmp        #$00ff+1        ;No. Bound check the result and
  1059.                 blt        @call_make_dib
  1060.  
  1061. @set_max        lda        #$00ff            ;Set to max if greater.
  1062. @call_make_dib    jsr        make_dib        ;Call routine to make the DIB RAM
  1063.                 bcc        @update_new        ;available.  ERROR?
  1064.                 cmp        #drvr_no_dev    ;Yes.  Then Exit
  1065.                 bne        @sec
  1066.                 clc
  1067.                 rts
  1068. @sec            sec
  1069.                 rts
  1070.                                         ;
  1071.                                         ; We had room in the current RAM
  1072.                                         ; Space so we will advance all the
  1073.                                         ; pointers to their next values
  1074.                                         ; within that space.
  1075.                                         ;
  1076. @adv_ptrs        clc
  1077.                 lda        <next_dib
  1078.                 sta        <last_dib
  1079.                 adc        #dib_size
  1080.                 sta        <next_dib
  1081.                 lda        <next_dib+2
  1082.                 sta        <last_dib+2
  1083.                 adc        #^dib_size
  1084.                 sta        <next_dib+2
  1085.                 jsr        dibicise_new_dib
  1086.                 bra        @exit
  1087.                                             ;
  1088.                                             ; We have a new memory segment so
  1089.                                             ; we need to account for this when
  1090.                                             ; we advance our pointers.
  1091.                                             ;
  1092. @update_new        stx        <first_dib
  1093.                 sty        <first_dib+2
  1094.                 lda        <next_dib
  1095.                 sta        <last_dib
  1096.                 lda        <next_dib+2
  1097.                 sta        <last_dib+2
  1098.                 clc                            ;Do Links Also
  1099.                 jsr        dibicise_new_ram
  1100.                                             ;
  1101.                                             ; Clean exit.
  1102.                                             ;
  1103. @exit            lda        |ram_page_cnt
  1104.                 clc
  1105.                 rts
  1106.  
  1107.                 ENDP
  1108.  
  1109.                 EJECT
  1110.  
  1111. ;____DIB_Building____
  1112. ;*******************************************************
  1113. ;
  1114. ;    REBLD_DIBS
  1115. ;
  1116. ;    It is the function of this routine to blindly
  1117. ;    rebuild the DIBs for the physical device attached to
  1118. ;    the current DIB.  If that device is non-partitioned,
  1119. ;    then only one DIB will be built, and a DISK SWITCHED
  1120. ;    will be issued.  If there are more than one device,
  1121. ;    as in partitioned media, then all the DIBs for the
  1122. ;    partitions will be re-built.  This is treated as if
  1123. ;    the device just came online for the first time.  If
  1124. ;    the new device has fewer partitions than there are
  1125. ;    DIBs that are already allocated, then the left over
  1126. ;    will be marked as being offline.  If, on the other
  1127. ;    hand, there are more partitions than DIBs, then new
  1128. ;    ones will be allocated and built.  These will then be
  1129. ;    permanantly linked to that physical device.
  1130. ;
  1131. ;    Inputs:        Acc            =    Unspecified
  1132. ;                Y register    =    Unspecified
  1133. ;                X register    =    Unspecified
  1134. ;                P register    =    0=M=X=e
  1135. ;                Direct Page    =    Ours
  1136. ;                Data Bank    =    Ours
  1137. ;
  1138. ;    Outputs:    Acc            =    Unspecified
  1139. ;                Y register    =    Unspecified
  1140. ;                X register    =    Unspecified
  1141. ;                P register    =    0=M=X=e
  1142. ;                Direct Page    =    Ours
  1143. ;                Data Bank    =    Ours
  1144. ;
  1145. ;    Errors:        Carry set if operation could not be
  1146. ;                completed.  Out of memory for example.
  1147. ;
  1148. ;*******************************************************
  1149.                                         ;
  1150.                                         ; Start of the code segment for this.
  1151.                                         ;
  1152.                 EXPORT    rebld_dibs
  1153. rebld_dibs        PROC
  1154.                                         ;
  1155.                                         ; Clear Linked Device Flag.  This will
  1156.                                         ; account for the situation where a
  1157.                                         ; partitioned disk has been reduced to
  1158.                                         ; a single volume.
  1159.                                         ;
  1160.                 stz        @linked
  1161.                                         ;
  1162.                                         ; Zero the count of new devices to be
  1163.                                         ; started.
  1164.                                         ;
  1165.                 stz        |new_dib_cnt
  1166.                                         ;
  1167.                                         ; Point to first DIB in link if any.
  1168.                                         ; If it is zero, then we are already
  1169.                                         ; there.
  1170.                                         ;
  1171.                 ldy        #dib.headptr+2
  1172.                 lda        [dib_ptr],y
  1173.                 ldy        #dib.headptr
  1174.                 ora        [dib_ptr],y
  1175.                 beq        @over
  1176.                                         ;
  1177.                                         ; It's non-zero.  Set up DIB_PTR
  1178.                                         ;
  1179.                 lda        [dib_ptr],y
  1180.                 tax
  1181.                 ldy        #dib.headptr+2
  1182.                 lda        [dib_ptr],y
  1183.                 sta        <dib_ptr+2
  1184.                 stx        <dib_ptr
  1185.                                         ;
  1186.                                         ; Set Temp Pointer to first DIB in the link.
  1187.                                         ;
  1188. @over            lda        <dib_ptr
  1189.                 sta        <scsi_zp6
  1190.                 lda        <dib_ptr+2
  1191.                 sta        <scsi_zp6+2 
  1192.                                         ;
  1193.                                         ; Mark each DIB in the link as offline
  1194.                                         ; and switched.
  1195.                                         ;
  1196. @loop            ldy        #dib.dvcflag
  1197.                 lda        [scsi_zp6],y
  1198.                 and        #(dvc_online++\
  1199.                         pdos_part)--\
  1200.                         $ffff
  1201.                 ora        #dvc_switch++\
  1202.                         dvc_hardofl
  1203.                 sta        [scsi_zp6],y
  1204.                                         ;
  1205.                                         ; Mark each DIB in the link as Unlinked.
  1206.                                         ;
  1207.                 ldy        #dib.dvcchar
  1208.                 lda        [scsi_zp6],y
  1209.                 and        #linked_dvc--\
  1210.                         $ffff
  1211.                 sta        [scsi_zp6],y
  1212.                                         ;
  1213.                                         ; Zero Partition Offset for each DIB
  1214.                                         ;
  1215.                 lda        #null
  1216.                 ldy        #dib.start_blk
  1217.                 sta        [scsi_zp6],y
  1218.                 ldy        #dib.start_blk+2
  1219.                 sta        [scsi_zp6],y
  1220.                                         ;
  1221.                                         ; It's non-zero.  Set up next DIB_PTR
  1222.                                         ;
  1223.                 clc
  1224.                 ldy        #dib.fdvcptr
  1225.                 lda        [scsi_zp6],y
  1226.                 tax
  1227.                 beq        @null
  1228.  
  1229.                 sec
  1230.  
  1231. @null            ldy        #dib.fdvcptr+2
  1232.                 lda        [scsi_zp6],y
  1233.                 bne        @doit
  1234.                 bcc        @over_0
  1235.  
  1236. @doit            sta        <scsi_zp6+2
  1237.                 stx        <scsi_zp6
  1238.  
  1239.                 bra        @loop
  1240.                                         ;
  1241.                                         ; Initialize a few values.
  1242.                                         ;
  1243. @over_0            lda        #$ffff            ;The following values will be incrimented
  1244.                 sta        |first_time        ;with zero indicating special action.
  1245.                 sta        |rebuild        ;This is set to $ffff so that it will only
  1246.                 sta        |only_one        ;occur on the first pass through.
  1247.  
  1248.                 stz        |part_cnt
  1249.                 stz        |pm_blk_num
  1250.                 stz        |new_dib
  1251.                                         ;
  1252.                                         ; MAIN LOOP OF CODE SEGMENT.
  1253.                                         ;
  1254. @main_loop        jsr        read_pm_blk
  1255.                 bcc        @with_data        ;This device is with data
  1256.                 lda        auto_sense_data+\        ;Is it an audio disk?
  1257.                         rqst_sens.addnl_sens_code
  1258.                 and        #$00fe            ;Checking for $84, $64, or $63
  1259.                 cmp        #$0064            ;This cover $63, $64
  1260.                 beq        @single
  1261.                 cmp        #$0084
  1262.                 beq        @single
  1263.                 sec
  1264.                 rts                        ;There was an error!
  1265.                                         ;
  1266.                                         ; Valid Partition Map?
  1267.                                         ;
  1268. @with_data        jsr        chk_map
  1269.                 bcs        @done
  1270.                 bne        @main
  1271.                                         ;
  1272.                                         ; We have a vaild Partition Map so
  1273.                                         ; we need to make an entry for each
  1274.                                         ; partition other than those with
  1275.                                         ; the partition types of 'MAP',
  1276.                                         ; 'SCRATCH', and 'FREE'.  All others
  1277.                                         ; will be considered valid.  We also
  1278.                                         ; only accept up to 'max_partitions'
  1279.                                         ; partitions per disk.
  1280.                                         ;
  1281.                                         ; How many partitions are there?
  1282.                                         ;
  1283.                 lda        |pm.MapBlkCnt\
  1284.                         +internal_buff
  1285.                 bne        @force_max
  1286.                 lda        |pm.MapBlkCnt+2\
  1287.                         +internal_buff
  1288.                 xba                        ;Value is High --> Low
  1289.                 cmp        #max_partitions+1
  1290.                 blt        @cnt_ok
  1291. @force_max        lda        #max_partitions
  1292. @cnt_ok            sta        |part_cnt
  1293.  
  1294.                 cmp        #$0002+1
  1295.                 blt        @non_linked
  1296.                 dec        @linked
  1297. @non_linked        dec        |part_cnt
  1298.                 bpl        @main
  1299.                                         ;
  1300.                                         ; No valid entry.  Set as if no
  1301.                                         ; partitions.
  1302.                                         ;
  1303.                 jsr        no_partition
  1304.                 jsr        trash_volume    ;Trash the volume if caller wishes.
  1305.                                         ;See |trash_it flag in trash_volume
  1306.                                         ;
  1307.                                         ; Mark DIB as online and switched.
  1308.                                         ;
  1309. @single            ldy        #dib.dvcflag
  1310.                 lda        [dib_ptr],y
  1311.                 and        #dvc_hardofl--\
  1312.                         $ffff
  1313.                 ora        #dvc_switch++\
  1314.                         dvc_online
  1315.                 sta        [dib_ptr],y
  1316.  
  1317.                 lda        #null
  1318.                 clc
  1319.                 rts
  1320.                                         ;
  1321.                                         ; Check validity of partiton map.
  1322.                                         ;
  1323. @main            jsr        check_map_entry
  1324.                 bcc        @chk_pdos
  1325.                                         ;
  1326.                                         ; It was undefined or unusable
  1327.                                         ;
  1328.                                         ; Is the Pointer good?
  1329.                                         ;
  1330.                                         ; Is it a cold DIB?
  1331.                                         ;
  1332.                 ldy        #dib.dvcflag
  1333.                 lda        [add_dib_here],y
  1334.                 and        #cold_dib
  1335.                 beq        @over_cold        ;No.  Skip clear code.
  1336.                                         ;
  1337.                                         ; Mark DIB to the Default.
  1338.                                         ;
  1339.                 ldy        #dib.dvcflag
  1340.                 lda        #wait_mode++\    ; Wait Mode is default
  1341.                         cold_dib        ; and they start cold.
  1342.                 sta        [add_dib_here],y
  1343.                                         ;
  1344.                                         ; Must set Head Link Ptr, Forward
  1345.                                         ; Device Link Ptr, and DIB Device
  1346.                                         ; Number to Null.
  1347.                                         ;
  1348.                 lda        #null
  1349.  
  1350.                 ldy        #dib.devnum
  1351.                 sta        [add_dib_here],y
  1352.  
  1353.                 ldy        #dib.headlnk
  1354.                 sta        [add_dib_here],y
  1355.  
  1356.                 ldy        #dib.fdvclnk
  1357.                 sta        [add_dib_here],y
  1358.                                         ;
  1359.                                         ; And skip it.
  1360.                                         ; Is there more to do?
  1361.                                         ;
  1362. @over_cold        dec        |part_cnt
  1363.                 bmi        @do_dpi            ;No!
  1364.                 jmp        @main_loop        ;Yes!
  1365.                                         ;
  1366.                                         ; Check to see if the post driver install
  1367.                                         ; list contains any entries.
  1368.                                         ;
  1369. @do_dpi            jsr        do_post_install        
  1370.                                         ;
  1371.                                         ; Check the only one flag.  If true
  1372.                                         ; then unlink it.
  1373.                                         ;
  1374.                 lda        |only_one
  1375.                 bne        @done
  1376.  
  1377.                 ldy        #dib.dvcchar
  1378.                 lda        [rebuild_zp],y
  1379.                 and        #linked_dvc--\
  1380.                         $ffff
  1381.                 sta        [rebuild_zp],y
  1382.                                         ;
  1383.                                         ; Clean exit.
  1384.                                         ;
  1385. @done            clc
  1386. @rts            rts
  1387.                                         ;
  1388.                                         ; Check the Overflow bit.  If it is set,
  1389.                                         ; then this is a ProDOS Partition and we
  1390.                                         ; need to set the correct bit in the DIB.
  1391.                                         ;
  1392. @chk_pdos        bvc        @over_1
  1393.                                         ;
  1394.                                         ; Set the ProDOS Bit.
  1395.                                         ;
  1396.                 ldy        #dib.dvcflag
  1397.                 lda        [dib_ptr],y
  1398.                 ora        #pdos_part
  1399.                 sta        [dib_ptr],y
  1400.                                         ;
  1401.                                         ; Issue call to fix unit 1.  This will
  1402.                                         ; guarantee that the first unit is also
  1403.                                         ; the first ProDOS Partition on the disk.
  1404.                                         ;
  1405.                 jsr        fix_unit_1
  1406.                                         ;
  1407.                                         ; Get the Block Count for this
  1408.                                         ; Partition and store it in the
  1409.                                         ; DIB.  The count as it exists
  1410.                                         ; in the partition data is stored
  1411.                                         ; High byte to Low byte.  We will
  1412.                                         ; need to alter this to Low --> High
  1413.                                         ; format.
  1414.                                         ;
  1415. @over_1            ldy        #dib.blkcnt
  1416.                 lda        |pm.PartBlkCnt+2\
  1417.                         +internal_buff
  1418.                 xba
  1419.                 sta        [dib_ptr],y
  1420.                 ldy        #dib.blkcnt+2
  1421.                 lda        |pm.PartBlkCnt\
  1422.                         +internal_buff
  1423.                 xba
  1424.                 sta        [dib_ptr],y
  1425.                                         ;
  1426.                                         ; Now we need to get the starting
  1427.                                         ; location for this partition.  This
  1428.                                         ; will be added to the requested
  1429.                                         ; block to generate a real block
  1430.                                         ; address.  Also in High --> Low format.
  1431.                                         ;
  1432.                 ldy        #dib.start_blk+2
  1433.                 lda        |pm.PyPartStart+2\
  1434.                         +internal_buff
  1435.                 sta        [dib_ptr],y
  1436.                 ldy        #dib.start_blk
  1437.                 lda        |pm.PyPartStart\
  1438.                         +internal_buff
  1439.                 sta        [dib_ptr],y
  1440.                                         ;
  1441.                                         ; Get Location of this partition on disk.
  1442.                                         ;
  1443.                 ldy        #dib.part_blk
  1444.                 lda        |pm_blk_num
  1445.                 sta        [dib_ptr],y
  1446.                                         ;
  1447.                                         ; Mark DIB as online and switched.
  1448.                                         ;
  1449.                 ldy        #dib.dvcflag
  1450.                 lda        [dib_ptr],y
  1451.                 and        #dvc_hardofl--\
  1452.                         $ffff
  1453.                 ora        #dvc_switch++\
  1454.                         dvc_online
  1455.                 sta        [dib_ptr],y
  1456.                                         ;
  1457.                                         ; Mark DIB as Linked.
  1458.                                         ;
  1459.                 lda        @linked
  1460.                 bpl        @skip_link
  1461.                 ldy        #dib.dvcchar
  1462.                 lda        [dib_ptr],y
  1463.                 ora        #linked_dvc
  1464.                 sta        [dib_ptr],y
  1465.                                         ;
  1466.                                         ; Inc the ONLY_ONE Flag.  If it is
  1467.                                         ; null then save the dib_ptr.  On
  1468.                                         ; exit we will check this flag and
  1469.                                         ; if = 0 we will use this pointer
  1470.                                         ; to clear the linked flag.
  1471.                                         ;
  1472.                 inc        |only_one
  1473.                 bne        @skip_link
  1474.  
  1475.                 lda        <dib_ptr
  1476.                 sta        <rebuild_zp
  1477.                 lda        <dib_ptr+2
  1478.                 sta        <rebuild_zp+2
  1479.                                         ;
  1480.                                         ; Wipe out block 2 of partition or
  1481.                                         ; volume
  1482.                                         ;
  1483. @skip_link        jsr        trash_volume
  1484.                                         ;
  1485.                                         ; Is this a new dib?
  1486.                                         ;
  1487.                 bit        |new_dib
  1488.                 bpl        @set_dsw        ;No.  Set disk switch
  1489.  
  1490.                 ldx        <dib_ptr
  1491.                 ldy        <dib_ptr+2
  1492.                 jsr        add_dib_ptr        ;Yes. Add to the list for post driver
  1493.                 bra        @over_dsw        ; install.
  1494.                                         ;
  1495.                                         ; Set the DISK SWITCHED
  1496.                                         ;
  1497. @set_dsw
  1498. ;                jsr        set_disk_sw
  1499.                                         ;
  1500.                                         ; Is there more to do?
  1501.                                         ;
  1502. @over_dsw        stz        |new_dib
  1503.                 dec        |part_cnt
  1504.                 bpl        @over_do_dpi    ;Yes!
  1505.                 jmp        @do_dpi            ;No!
  1506.                                         ;
  1507.                                         ; All done with the DIB Update now
  1508.                                         ; do we have any more DIBs, for this
  1509.                                         ; linked device?
  1510.                                         ;
  1511. @over_do_dpi    ldy        #dib.fdvcptr
  1512.                 lda        [dib_ptr],y
  1513.                 tax
  1514.  
  1515.                 ldy        #dib.fdvcptr+2
  1516.                 ora        [dib_ptr],y
  1517.                 beq        @over_2
  1518.                 lda        [dib_ptr],y
  1519.  
  1520.                 sta        <dib_ptr+2
  1521.                 stx        <dib_ptr
  1522.                                         ;
  1523.                                         ; Do the next one.
  1524.                                         ;
  1525. @jmp_main        jmp        @main_loop
  1526.                                         ;
  1527.                                         ; It's zero.  Need to add DIBs
  1528.                                         ;
  1529.                                         ; Is there an empty DIB some where?
  1530.                                         ;
  1531. @over_2            jsr        find_empty
  1532.                 bcc        @found_empty
  1533.                                         ;
  1534.                                         ; Get room for some more DIBs.
  1535.                                         ;
  1536.                 jsr        add_dib_ram
  1537.                 bcc        @over_2
  1538.                 
  1539.  
  1540.                 rts
  1541.                                         ;
  1542.                                         ; We need to set some pointers for
  1543.                                         ; the routines that we will be
  1544.                                         ; calling.  These pointers are similar
  1545.                                         ; to those used in the startup code
  1546.                                         ;
  1547.                                         ; 1st.  Set the pointer to the next
  1548.                                         ; DIB to be build.
  1549.                                         ;
  1550. @found_empty    lda        <add_dib_here
  1551.                 sta        <dib_ptr
  1552.                 sta        <next_dib
  1553.                 lda        <add_dib_here+2
  1554.                 sta        <dib_ptr+2
  1555.                 sta        <next_dib+2
  1556.                                         ;
  1557.                                         ; Preserve the Link Pointer.  Otherwise
  1558.                                         ; it will be destroyed by the dibicise
  1559.                                         ; routine.
  1560.                                         ;
  1561.                 ldy        #dib.linkptr+2
  1562.                 lda        [next_dib]
  1563.                 pha
  1564.                 lda        [next_dib],y
  1565.                 pha
  1566.                                         ;
  1567.                                         ; Set the 'first_dib' pointer to the
  1568.                                         ; first dib in the same memory segment
  1569.                                         ; from the memory manager as the one
  1570.                                         ; that contains the space to be used
  1571.                                         ; for this new dib.  first we get the
  1572.                                         ; handle.
  1573.                                         ;
  1574.                 ldy        #dib.handle
  1575.                 lda        [next_dib],y
  1576.                 sta        <first_dib
  1577.  
  1578.                 ldy        #dib.handle+2
  1579.                 lda        [next_dib],y
  1580.                 sta        <first_dib+2
  1581.                                         ;
  1582.                                         ; then we deref the handle.
  1583.                                         ;
  1584.                 ldy        #$0002
  1585.                 lda        [first_dib]
  1586.                 tax
  1587.                 lda        [first_dib],y
  1588.                 sta        <first_dib+2
  1589.                 stx        <first_dib
  1590.                                         ;
  1591.                                         ; Tell the dibicize routine that this
  1592.                                         ; is not from the startup code.  This
  1593.                                         ; also forces the descriptive names
  1594.                                         ; minor id to be changed leaving the
  1595.                                         ; major or device portion as it is.
  1596.                                         ;
  1597.                 dec        |main_caller
  1598.                                         ;
  1599.                                         ; Dibicise the new dib.
  1600.                                         ;
  1601.                 jsr        dibicise_new_dib
  1602.                                         ;
  1603.                                         ; Restore the Link Pointer.  Otherwise
  1604.                                         ; it is destroyed by the dibicise
  1605.                                         ; routine.
  1606.                                         ;
  1607.                 ldy        #dib.linkptr+2
  1608.                 pla
  1609.                 sta        [next_dib],y
  1610.                 pla
  1611.                 sta        [next_dib]
  1612.                                         ;
  1613.                                         ; Rev the unit number to be unique
  1614.                                         ;
  1615.                 ldy        #dib.unitnum
  1616.                 lda        [next_dib],y
  1617.                 tax
  1618.                 and        #max_p_mask
  1619.                 cmp        #max_p_mask
  1620.                 beq        @all_done
  1621.  
  1622.                 txa
  1623.                 clc
  1624.                 adc        #p_mask_adder
  1625.                 sta        [next_dib],y
  1626.                                         ;
  1627.                                         ; This flag indicates that this is a
  1628.                                         ; new dib and that the routine that
  1629.                                         ; finalizes this dib will have to
  1630.                                         ; issue a post driver install call.
  1631.                                         ;
  1632.                 dec        |new_dib
  1633.                                         ;
  1634.                                         ; Go back to the main loop where this
  1635.                                         ; dib will be finalized and installed.
  1636.                                         ;
  1637.                 jmp        @main_loop
  1638.                                         ;
  1639.                                         ; Clean Exit
  1640.                                         ;
  1641. @all_done        clc
  1642.                 rts
  1643.                                         ;
  1644.                                         ; Misc Data for this sub-routine
  1645.                                         ;
  1646. @linked            dc.w        null
  1647. @part_num        dc.w        null
  1648. @vPart_cnt        dc.w        null
  1649.  
  1650.                 ENDP
  1651.  
  1652.                 EJECT
  1653.             
  1654. ;*******************************************************
  1655. ;
  1656. ;    'do_part_dib'
  1657. ;
  1658. ;    This routine issues a READ call to the device and
  1659. ;    then uses the data returned to check for any
  1660. ;    partitions on the media.  If partitions do exist, it
  1661. ;    then creates the needed dibs from those that have
  1662. ;    been allocated but unused, or if needed will create
  1663. ;    a new memory segment and continue on.
  1664. ;        
  1665. ;    Inputs:        <next_dib    =    Next DIB start        (LONG)
  1666. ;                Acc            =    Unspecified
  1667. ;                Carry        =    Unspecified
  1668. ;                Y register    =    Unspecified
  1669. ;                X register    =    Unspecified
  1670. ;                P register    =    0=M=X=e
  1671. ;                Direct Page    =    Ours
  1672. ;                Data Bank    =    Ours
  1673. ;
  1674. ;    Outputs:    <next_dib    =    last DIB Built        (LONG)
  1675. ;                Acc            =    Unspecified
  1676. ;                Carry        =    Unspecified
  1677. ;                Y register    =    Unspecified
  1678. ;                X register    =    Unspecified
  1679. ;                P register    =    0=M=X=e
  1680. ;                Direct Page    =    Ours
  1681. ;                Data Bank    =    Ours
  1682. ;
  1683. ;    Errors:        None.
  1684. ;
  1685. ;*******************************************************
  1686.                                         ;
  1687.                                         ; Start of the code segment for this.
  1688.                                         ;
  1689.                 EXPORT    do_part_dib
  1690. do_part_dib        PROC
  1691.  
  1692. ;-------------------------------------------------------------------------------
  1693.  
  1694.                 IF            part_suprt = true        THEN
  1695.  
  1696.                                         ;
  1697.                                         ; MAIN LOOP OF CODE SEGMENT.
  1698.                                         ;
  1699. @main_loop        jsr        read_pm_blk
  1700.                 bcc        @chk_map        ;Was there an error?
  1701.                 
  1702.                 jsr        no_partition                                        ;
  1703.                 bra        @done
  1704.                                         ; Valid Partition Map?
  1705.                                         ;
  1706. @chk_map        jsr        chk_map
  1707.                 bcs        @done
  1708.                 bne        @main
  1709.                                         ;
  1710.                                         ; We have a vaild Partition Map so
  1711.                                         ; we need to make an entry for each
  1712.                                         ; partition other than those with
  1713.                                         ; the partition types of 'MAP',
  1714.                                         ; 'SCRATCH', and 'FREE'.  All others
  1715.                                         ; will be considered valid.  We also
  1716.                                         ; only accept up to 'max_partitions'
  1717.                                         ; partitions per disk.
  1718.                                         ;
  1719.                                         ; How many partitions are there?
  1720.                                         ;
  1721.                 lda        |pm.MapBlkCnt\
  1722.                         +internal_buff
  1723.                 bne        @force_max
  1724.                 lda        |pm.MapBlkCnt+2\
  1725.                         +internal_buff
  1726.                 xba                        ;Value is High --> Low
  1727.                 cmp        #max_partitions+1
  1728.                 blt        @cnt_ok
  1729. @force_max        lda        #max_partitions
  1730. @cnt_ok            sta        |part_cnt
  1731.  
  1732.                 dec        |part_cnt
  1733.                 bpl        @main
  1734.                                         ;
  1735.                                         ; No valid entry.  Set as if no
  1736.                                         ; partitions.
  1737.                                         ;
  1738.                 jsr        no_partition
  1739.                 clc
  1740.                 rts
  1741.                                         ;
  1742.                                         ; Check validity of partiton map.
  1743.                                         ;
  1744. @main            jsr        check_map_entry
  1745.                 bcc        @chk_pdos
  1746.                                         ;
  1747.                                         ; It was undefined or unusable
  1748.                                         ; Mark DIB to the Default.
  1749.                                         ;
  1750.                 ldy        #dib.dvcflag
  1751.                 lda        #wait_mode++\    ; Wait Mode is default
  1752.                         cold_dib        ; and they start cold.
  1753.                 sta        [next_dib],y
  1754.                                         ;
  1755.                                         ; Must set Head Link Ptr, Forward
  1756.                                         ; Device Link Ptr, and DIB Device
  1757.                                         ; Number to Null.
  1758.                                         ;
  1759.                 lda        #null
  1760.  
  1761.                 ldy        #dib.devnum
  1762.                 sta        [next_dib],y
  1763.  
  1764.                 ldy        #dib.headlnk
  1765.                 sta        [next_dib],y
  1766.  
  1767.                 ldy        #dib.fdvclnk
  1768.                 sta        [next_dib],y
  1769.                                         ;
  1770.                                         ; And skip it.
  1771.                                         ; Is there more to do?
  1772.                                         ;
  1773.                 dec        |part_cnt
  1774.                 bpl        @main_loop
  1775.                                         ;
  1776.                                         ; Clean exit.
  1777.                                         ;
  1778. @done            clc
  1779. @rts            rts
  1780.                                         ;
  1781.                                         ; Check the Overflow bit.  If it is set,
  1782.                                         ; then this is a ProDOS Partition and we
  1783.                                         ; need to set the correct bit in the DIB.
  1784.                                         ;
  1785. @chk_pdos        bvc        @over
  1786.                                         ;
  1787.                                         ; Set the ProDOS Bit.
  1788.                                         ;
  1789.                 ldy        #dib.dvcflag
  1790.                 lda        [next_dib],y
  1791.                 ora        #pdos_part
  1792.                 sta        [next_dib],y
  1793.                                         ;
  1794.                                         ; Issue call to fix unit 1.  This will
  1795.                                         ; guarantee that the first unit is also
  1796.                                         ; the first ProDOS Partition on the disk.
  1797.                                         ;
  1798.                 jsr        fix_unit_1
  1799.                                         ;
  1800.                                         ; Get the Block Count for this
  1801.                                         ; Partition and store it in the
  1802.                                         ; DIB.  The count as it exists
  1803.                                         ; in the partition data is stored
  1804.                                         ; High byte to Low byte.  We will
  1805.                                         ; need to alter this to Low --> High
  1806.                                         ; format.
  1807.                                         ;
  1808. @over            ldy        #dib.blkcnt
  1809.                 lda        |pm.PartBlkCnt+2\
  1810.                         +internal_buff
  1811.                 xba
  1812.                 sta        [next_dib],y
  1813.                 ldy        #dib.blkcnt+2
  1814.                 lda        |pm.PartBlkCnt\
  1815.                         +internal_buff
  1816.                 xba
  1817.                 sta        [next_dib],y
  1818.                                         ;
  1819.                                         ; Now we need to get the starting
  1820.                                         ; location for this partition.  This
  1821.                                         ; will be added to the requested
  1822.                                         ; block to generate a real block
  1823.                                         ; address.  Also in High --> Low format.
  1824.                                         ;
  1825.                 ldy        #dib.start_blk+2
  1826.                 lda        |pm.PyPartStart+2\
  1827.                         +internal_buff
  1828.                 sta        [next_dib],y
  1829.                 ldy        #dib.start_blk
  1830.                 lda        |pm.PyPartStart\
  1831.                         +internal_buff
  1832.                 sta        [next_dib],y
  1833.                                         ;
  1834.                                         ; Get Location of this partition on disk.
  1835.                                         ;
  1836.                 ldy        #dib.part_blk
  1837.                 lda        |pm_blk_num
  1838.                 sta        [next_dib],y
  1839.                                         ;
  1840.                                         ; Set this device to ONLINE.
  1841.                                         ;
  1842.                 ldy        #dib.dvcflag
  1843.                 lda        [next_dib],y
  1844.                 ora        #dvc_online
  1845.                 sta        [next_dib],y
  1846.                                         ;
  1847.                                         ; Increment the partition count.
  1848.                                         ;                                        
  1849.                 inc        |part_num
  1850.                 beq        @chk_ram
  1851.                                         ;
  1852.                                         ; Update the High seven bits of the
  1853.                                         ; unit number checking for the max
  1854.                                         ; value of 'max_partitions'.
  1855.                                         ;
  1856.                 ldy        #dib.unitnum
  1857.                 lda        [next_dib],y
  1858.                 tax
  1859.                 and        #max_p_mask
  1860.                 cmp        #max_p_mask
  1861.                 beq        @all_done
  1862.                 txa
  1863.                 clc
  1864.                 adc        #p_mask_adder
  1865.                 sta        [next_dib],y
  1866.                 inc        |vPart_cnt
  1867.                                         ;
  1868.                                         ; All done with the DIB Update now
  1869.                                         ; do we have any more DIBs, and if
  1870.                                         ; so, do we have any more RAM left
  1871.                                         ; to build further DIBs?
  1872.                                         ;
  1873. @chk_ram        dec        |part_cnt        
  1874.                 bmi        @all_done
  1875.                 dec        |main_caller
  1876.                 jsr        chk_ram
  1877.                 bcs        @bad_call        ;ERROR?
  1878.                 jmp        @main_loop        ;No. Do the next one.
  1879. @bad_call        cmp        #drvr_no_dev    ;Yes.  Then Exit
  1880.                 bne        @sec
  1881.                 clc
  1882.                 rts
  1883. @sec            sec
  1884.                 rts
  1885.                                         ;
  1886.                                         ; Clean Exit
  1887.                                         ;
  1888. @all_done        clc
  1889.                 rts
  1890.  
  1891.                 ELSE
  1892.  
  1893. ;-------------------------------------------------------------------------------
  1894.  
  1895.                                         ;
  1896.                                         ; Clean Exit
  1897.                                         ;
  1898.                 lda        #null
  1899.                 clc
  1900.                 rts
  1901.  
  1902.                 ENDIF
  1903.  
  1904. ;-------------------------------------------------------------------------------
  1905.  
  1906.                 ENDP
  1907.  
  1908.                 EJECT
  1909.             
  1910. ;*******************************************************
  1911. ;
  1912. ;    'dibicise_new_ram'
  1913. ;
  1914. ;    This routine takes the DIB located at [last_dib] and
  1915. ;    copies it into the new ram space.  It does this
  1916. ;    while preserving the handle at offset 'dib.handle'.
  1917. ;    By so doing, it will be possible to free this ram
  1918. ;    space at some later time if that is deemed correct.
  1919. ;        
  1920. ;    Inputs:        <last_dib        =    Last DIB built        (LONG)
  1921. ;                <first_dib        =    Pointer to new        (LONG)
  1922. ;                                    ram space.
  1923. ;                Acc                =    Unspecified
  1924. ;                Carry    Clear    =    Do Link Pointers
  1925. ;                        Set        =    Skip Link Pointers
  1926. ;                Y register        =    Unspecified
  1927. ;                X register        =    Unspecified
  1928. ;                P register        =    0=M=X=e
  1929. ;                Direct Page        =    Ours
  1930. ;                Data Bank        =    Ours
  1931. ;
  1932. ;    Outputs:    <last_dib        =    unchanged            (LONG)
  1933. ;                <first_dib        =    unchanged            (LONG)
  1934. ;                <next_dib        =    <first_dib            (LONG)
  1935. ;                |curr_hndl        =    Handle for new ram    (LONG)
  1936. ;
  1937. ;                Acc                =    Unspecified
  1938. ;                Carry            =    Unspecified
  1939. ;                Y register        =    Unspecified
  1940. ;                X register        =    Unspecified
  1941. ;                P register        =    0=M=X=e
  1942. ;                Direct Page        =    Ours
  1943. ;                Data Bank        =    Ours
  1944. ;
  1945. ;        If Carry Set on entry then
  1946. ;
  1947. ;                |tot_dib_cnt    =    $0000                (WORD)
  1948. ;
  1949. ;        If Carry Clear on entry then
  1950. ;
  1951. ;                [last_dib]        =    points to this DIB    (LONG)
  1952. ;                [first_dib]        =    defaults set        (PTR)
  1953. ;                'Int Pntrs'        =    Set to this DIB        (LONG)s
  1954. ;                'dispname'        =    Device Name            (STR)
  1955. ;                |tot_dib_cnt    =    # of valid DIBs        (WORD)
  1956. ;
  1957. ;    Errors:        None.
  1958. ;
  1959. ;*******************************************************
  1960.  
  1961.                 EXPORT    dibicise_new_ram
  1962. dibicise_new_ram    PROC
  1963.                                             ;
  1964.                                             ; Save Do Links Flag.
  1965.                                             ;
  1966.                 php
  1967.                                             ;
  1968.                                             ; Preserve Handle for this
  1969.                                             ; memory segment.
  1970.                                             ;
  1971.                 ldy        #dib.handle
  1972.                 lda        [first_dib],y
  1973.                 sta        |curr_hndl
  1974.                 ldy        #dib.handle+2
  1975.                 lda        [first_dib],y
  1976.                 sta        |curr_hndl+2
  1977.                                             ;
  1978.                                             ; Using the built in move routine,
  1979.                                             ; copy the last DIB built to the 
  1980.                                             ; first_dib location for the next
  1981.                                             ; dib to be built.
  1982.                                             ;
  1983.                 pushlong    <last_dib
  1984.                 pushlong    <first_dib
  1985.                 pushlong    #dib_size
  1986.                 pushword    #move_sinc_dinc
  1987.  
  1988.                 jsl        move_info            ;Move the data
  1989.                                             ;
  1990.                                             ; Restore the handle to it's
  1991.                                             ; origonal location.  This will
  1992.                                             ; then be copied to every other
  1993.                                             ; dib that is built in this
  1994.                                             ; memory segment.
  1995.                                             ;
  1996.                 ldy        #dib.handle
  1997.                 lda        |curr_hndl
  1998.                 sta        [first_dib],y
  1999.                 ldy        #dib.handle+2
  2000.                 lda        |curr_hndl+2
  2001.                 sta        [first_dib],y
  2002.                                             ;
  2003.                                             ; Set 'next_dib' pointer to the
  2004.                                             ; first dib in this memory
  2005.                                             ; segment.
  2006.                                             ;
  2007.                 lda        <first_dib
  2008.                 sta        <next_dib
  2009.                 lda        <first_dib+2
  2010.                 sta        <next_dib+2
  2011.  
  2012.                 ldy        #dib.dvcflag
  2013.                 lda        [first_dib],y
  2014.                 ora        #cold_dib            ;New DIB.  Do Cold Start.
  2015.                 sta        [first_dib],y
  2016.                                             ;
  2017.                                             ; Reinitialise mem_dib_cnt to zero.
  2018.                                             ;
  2019.                 lda        #null
  2020.                 ldy        #dib.mem_dib_cnt
  2021.                 sta        [first_dib],y
  2022.                                             ;
  2023.                                             ; Reinitialise DIB Dev Number also.
  2024.                                             ;
  2025.                 ldy        #dib.devnum
  2026.                 sta        [first_dib],y
  2027.                                             ;
  2028.                                             ; Finalise the new DIB Structure?
  2029.                                             ;
  2030.                 plp
  2031.                 bcc        set_link_ptrs
  2032.                 rts
  2033.  
  2034.                 ENDP
  2035.  
  2036.                 EJECT
  2037.             
  2038. ;*******************************************************
  2039. ;
  2040. ;    'dibicise_new_dib'
  2041. ;
  2042. ;    This routine takes the DIB located at [last_dib] and
  2043. ;    copies it into the new ram space.
  2044. ;        
  2045. ;    Inputs:        <last_dib    =    Last DIB built        (LONG)
  2046. ;                <next_dib    =    Next DIB start        (LONG)
  2047. ;                Acc            =    Unspecified
  2048. ;                Carry        =    Unspecified
  2049. ;                Y register    =    Unspecified
  2050. ;                X register    =    Unspecified
  2051. ;                P register    =    0=M=X=e
  2052. ;                Direct Page    =    Ours
  2053. ;                Data Bank    =    Ours
  2054. ;
  2055. ;    Outputs:    <last_dib    =    unchanged            (LONG)
  2056. ;                <next_dib    =    unchanged            (LONG)
  2057. ;                [last_dib]    =    points to this DIB    (LONG)
  2058. ;                [next_dib]    =    defaults set        (PTR)
  2059. ;                'Int Pntrs'    =    Set to this DIB        (LONG)s
  2060. ;                'dispname'    =    Device Name            (STR)
  2061. ;                |tot_dib_cnt=    # of valid DIBs        (WORD)
  2062. ;                Acc            =    Unspecified
  2063. ;                Carry        =    Unspecified
  2064. ;                Y register    =    Unspecified
  2065. ;                X register    =    Unspecified
  2066. ;                P register    =    0=M=X=e
  2067. ;                Direct Page    =    Ours
  2068. ;                Data Bank    =    Ours
  2069. ;
  2070. ;    Errors:        None.
  2071. ;
  2072. ;*******************************************************
  2073.  
  2074.                 EXPORT    dibicise_new_dib
  2075. dibicise_new_dib    PROC
  2076.                                             ;
  2077.                                             ; Using the built in move routine,
  2078.                                             ; copy the last DIB built to the 
  2079.                                             ; next_dib location for the next
  2080.                                             ; dib to be built.
  2081.                                             ;
  2082.                 pushlong    <last_dib
  2083.                 pushlong    <next_dib
  2084.                 pushlong    #dib_size
  2085.                 pushword    #move_sinc_dinc
  2086.  
  2087.                 jsl        move_info            ;Move the data
  2088.  
  2089.                                             ;
  2090.                                             ; Finalise the new DIB Structure.
  2091.                                             ;
  2092.                 EXPORT    set_link_ptrs
  2093.                                             ;
  2094.                                             ; Update Links and DIB ext ptrs
  2095.                                             ;
  2096. set_link_ptrs    bit        |rebuild
  2097.                 bmi        @rebuild_links
  2098.  
  2099.                 clc                            ;we are going to add
  2100.                 lda        <next_dib            ;get low word of this dib
  2101.                 sta        [last_dib]            ;store in last dib (implied y = 0)
  2102.  
  2103.                 adc        #dib.start_blk        ;adc offset to ext dib ptr
  2104.                 ldy        #dib.ext_ptr        ;get offset to where this goes
  2105.                 sta        [next_dib],y        ;and store low word of ptr
  2106.  
  2107.                 ldy        #dib.linkptr+2        ;get offset to high word
  2108.                 lda        <next_dib+2            ;get the high word and
  2109.                 sta        [last_dib],y        ;store it in the last dib
  2110.  
  2111.                 adc        #^dib.start_blk        ;adc high offset to ext ptr
  2112.                 ldy        #dib.ext_ptr+2        ;get offset to where this goes
  2113.                 sta        [next_dib],y        ;and store the high word ptr
  2114.                                             ;
  2115.                                             ; Zero out the Link for this DIB
  2116.                                             ;
  2117.                 lda        #null
  2118.                 ldy        #dib.linkptr
  2119.                 sta        [next_dib],y
  2120.                 ldy        #dib.linkptr+2
  2121.                 sta        [next_dib],y
  2122.                                             ;
  2123.                                             ; Zero out the Starting Block for this DIB
  2124.                                             ;
  2125. @rebuild_links    lda        #null
  2126.                 ldy        #dib.start_blk
  2127.                 sta        [next_dib],y
  2128.                 ldy        #dib.start_blk+2
  2129.                 sta        [next_dib],y
  2130.                                             ;
  2131.                                             ; Increment the number of active DIBs in
  2132.                                             ; this memory segement.
  2133.                                             ;
  2134.                 ldy        #dib.mem_dib_cnt
  2135.                 lda        [first_dib],y
  2136.                 inc        a
  2137.                 sta        [first_dib],y
  2138.                                             ;
  2139.                                             ; In the DIB Extension as defined for this
  2140.                                             ; driver is the root structure of the
  2141.                                             ; pointers that are used to call the SCSI
  2142.                                             ; Manager.  At this time we need to update
  2143.                                             ; them so that they too point into this
  2144.                                             ; dib and not the last one.
  2145.                                             ;
  2146.                 clc
  2147.                 lda        <next_dib            ;Low word of Completion Pointer
  2148.                 adc        #dib.complet
  2149.                 ldy        #dib.compvec
  2150.                 sta        [next_dib],y
  2151.  
  2152.                 lda        <next_dib+2            ;High word of Completion Pointer
  2153.                 adc        #^dib.complet
  2154.                 ldy        #dib.compvec+2
  2155.                 sta        [next_dib],y
  2156.  
  2157.                 clc
  2158.                 lda        <next_dib            ;Low word of Command Packet Pointer
  2159.                 adc        #dib.scsicmd
  2160.                 ldy        #dib.cp_ptr
  2161.                 sta        [next_dib],y
  2162.  
  2163.                 lda        <next_dib+2            ;High word of Command Packet Pointer
  2164.                 adc        #^dib.scsicmd
  2165.                 ldy        #dib.cp_ptr+2
  2166.                 sta        [next_dib],y
  2167.  
  2168.                 clc
  2169.                 lda        <next_dib            ;Low word of Send Structure Pointer
  2170.                 adc        #dib.trx_buff
  2171.                 ldy        #dib.trx_ptr
  2172.                 sta        [next_dib],y
  2173.  
  2174.                 lda        <next_dib+2            ;High word of Send Structure Pointer
  2175.                 adc        #^dib.trx_buff
  2176.                 ldy        #dib.trx_ptr+2
  2177.                 sta        [next_dib],y
  2178.                                             ;
  2179.                                             ; Were we called from the
  2180.                                             ; main outside loop?
  2181.                                             ;
  2182.                 lda        |main_caller
  2183.                 bne        @skip_links            ; No.  Do device links.
  2184.                                             ;
  2185.                                             ; Zero out the HEAD LINK and FORWARD LINK
  2186.                                             ; pointers.
  2187.                                             ;
  2188.                 ldy        #dib.headlnk
  2189.                 sta        [next_dib],y        ;Acc = 0. See Load.
  2190.                 ldy        #dib.fdvclnk
  2191.                 sta        [next_dib],y
  2192.                 ldy        #dib.headptr
  2193.                 sta        [next_dib],y        ;Acc = 0. See Load.
  2194.                 ldy        #dib.fdvcptr
  2195.                 sta        [next_dib],y
  2196.                 ldy        #dib.headptr+2
  2197.                 sta        [next_dib],y        ;Acc = 0. See Load.
  2198.                 ldy        #dib.fdvcptr+2
  2199.                 sta        [next_dib],y
  2200.                                             ;
  2201.                                             ; Set slot and device words in dib
  2202.                                             ;
  2203.                 lda        [dvc_list]
  2204.  
  2205.                 ldy        #dib.slotnum
  2206.                 sta        [next_dib],y
  2207.  
  2208.                 ldy        #$0002
  2209.                 lda        [dvc_list],y
  2210.  
  2211.                 ldy        #dib.unitnum
  2212.                 sta        [next_dib],y
  2213.                                             ;
  2214.                                             ; Set pointer to the descriptive or
  2215.                                             ; device name so that we can rev the
  2216.                                             ; name to prevent duplicates.
  2217.                                             ;
  2218. @skip_links        clc
  2219.                 lda        <next_dib
  2220.                 adc        #dib.namelen
  2221.                 sta        <scsi_zp0
  2222.                 lda        <next_dib+2
  2223.                 adc        #^dib.namelen
  2224.                 sta        <scsi_zp0+2
  2225.                                             ;
  2226.                                             ; Was internal or externally called?
  2227.                                             ; If internal, then we need to update
  2228.                                             ; the major revision part of the
  2229.                                             ; descriptive name.  If it was external,
  2230.                                             ; then we will update the minor revision
  2231.                                             ; part only.
  2232.                                             ;
  2233.                 lda        |main_caller
  2234.                 beq        @do_major
  2235.                                             ;
  2236.                                             ; Do the minor revision.
  2237.                                             ;
  2238.                 jsr        minor_update
  2239.                 bra        @clear_busy
  2240.                                             ;
  2241.                                             ; Do the major revision.
  2242.                                             ;
  2243. @do_major        jsr        major_update
  2244.                                             ;
  2245.                                             ; Clear artifacts.  We copied this data
  2246.                                             ; from the first dib that has the
  2247.                                             ; call_active bit set.  Clear the sucker.
  2248.                                             ;
  2249. @clear_busy        ldy        #dib.dvcchar
  2250.                 lda        [next_dib],y
  2251.                 and        #call_active--\
  2252.                         $ffff
  2253.                 sta        [next_dib],y
  2254.                                             ;
  2255.                                             ; Clear the ProDOS Bit.
  2256.                                             ;
  2257.                 ldy        #dib.dvcflag
  2258.                 lda        [next_dib],y
  2259.                 and        #pdos_part--\
  2260.                         $ffff
  2261.                 sta        [next_dib],y
  2262.                                             ;
  2263.                                             ; Inc the DIB Count at this point.
  2264.                                             ; Every DIB that is succesfully built
  2265.                                             ; will be modified by the above code.
  2266.                                             ;
  2267.                 stz        |main_caller
  2268.                 inc        |tot_dib_cnt
  2269.                 clc
  2270.                 rts
  2271.  
  2272.                 ENDP
  2273.  
  2274.                 EJECT
  2275.  
  2276. ;*******************************************************
  2277. ;
  2278. ;    MAJOR_UPDATE
  2279. ;
  2280. ;    This routine updates the major revision portion of
  2281. ;    the descriptive name portion of the DIB.
  2282. ;
  2283. ;    Inputs:        <DIB_PTR        =    DIB Location
  2284. ;                Acc                =    Unspecified
  2285. ;                Y register        =    Unspecified
  2286. ;                X register        =    Unspecified
  2287. ;                P register        =    0=M=X=e
  2288. ;                Direct Page        =    Ours
  2289. ;                Data Bank        =    Ours
  2290. ;
  2291. ;    Outputs:    Acc                =    Unspecified
  2292. ;                Y register        =    Unspecified
  2293. ;                X register        =    Unspecified
  2294. ;                P register        =    0=M=X=e
  2295. ;                Direct Page        =    Ours
  2296. ;                Data Bank        =    Ours
  2297. ;
  2298. ;    Errors:        Better be none.
  2299. ;
  2300. ;*******************************************************
  2301.  
  2302.                 EXPORT    major_update
  2303. major_update    PROC
  2304.                                     ;
  2305.                                     ; Change name so as not to conflict
  2306.                                     ; with any other name already built.
  2307.                                     ; All names end with '00' - '99'.
  2308.                                     ;
  2309.                 short
  2310.  
  2311.                 ldx        #$02        ;Don't change this value.
  2312.                 sec
  2313.                 lda        [scsi_zp0]
  2314.                                     ;
  2315.                                     ; Reset Minor Revision to '00'.
  2316.                                     ;
  2317.                 pha
  2318.                 tay
  2319.                 lda        #'0'
  2320.                 sta        [scsi_zp0],y
  2321.                 dey
  2322.                 sta        [scsi_zp0],y
  2323.                 pla
  2324.  
  2325.                 sbc        #$03
  2326.                 tay
  2327. @name_loop        lda        [scsi_zp0],y
  2328.                 inc        a
  2329.                 cmp        #'9'+1
  2330.                 blt        @update
  2331.                 lda        #'0'
  2332.                 dex
  2333. @update            sta        [scsi_zp0],y
  2334.                 dey
  2335.                 dex
  2336.                 beq        @name_loop
  2337.  
  2338.                 longmx
  2339.  
  2340.                 rts
  2341.  
  2342.                 ENDP
  2343.  
  2344.                 EJECT
  2345.  
  2346. ;*******************************************************
  2347. ;
  2348. ;    MINOR_UPDATE
  2349. ;
  2350. ;    This routine updates the minor revision portion of
  2351. ;    the descriptive name portion of the DIB.
  2352. ;
  2353. ;    Inputs:        <DIB_PTR        =    DIB Location
  2354. ;                Acc                =    Unspecified
  2355. ;                Y register        =    Unspecified
  2356. ;                X register        =    Unspecified
  2357. ;                P register        =    0=M=X=e
  2358. ;                Direct Page        =    Ours
  2359. ;                Data Bank        =    Ours
  2360. ;
  2361. ;    Outputs:    Acc                =    Unspecified
  2362. ;                Y register        =    Unspecified
  2363. ;                X register        =    Unspecified
  2364. ;                P register        =    0=M=X=e
  2365. ;                Direct Page        =    Ours
  2366. ;                Data Bank        =    Ours
  2367. ;
  2368. ;    Errors:        Better be none.
  2369. ;
  2370. ;*******************************************************
  2371.  
  2372.                 EXPORT    minor_update
  2373. minor_update    PROC
  2374.                                     ;
  2375.                                     ; Change name so as not to conflict
  2376.                                     ; with any other name already built.
  2377.                                     ; All names end with '00' - '99'.
  2378.                                     ;
  2379.                 short
  2380.  
  2381.                 ldx        #$02        ;Don't change this value.
  2382.                 lda        [scsi_zp0]
  2383.                                     ;
  2384.                                     ; Check the length of the string.  If
  2385.                                     ; it is different from the one in the
  2386.                                     ; Default DIB, then we need to assume
  2387.                                     ; that it has been renamed.  In this
  2388.                                     ; case, we will crank the count up by
  2389.                                     ; 2 but not past the max count of 31
  2390.                                     ; and append the version number
  2391.                                     ; change to that.
  2392.                                     ;
  2393.                 cmp        |default_dib+\
  2394.                         dib.namelen
  2395.                 beq        @len_ok
  2396.                                     ;
  2397.                                     ; Has it already been adjusted?
  2398.                                     ;
  2399.                 tay
  2400.                 lda        [scsi_zp0],y
  2401.                 cmp        #'0'
  2402.                 blt        @fix_it
  2403.                 cmp        #'9'+1
  2404.                 bge        @fix_it
  2405.                 dey
  2406.                 lda        [scsi_zp0],y
  2407.                 cmp        #'0'
  2408.                 blt        @fix_it
  2409.                 cmp        #'9'+1
  2410.                 bge        @fix_it
  2411.                 iny
  2412.                 bra        @name_loop
  2413.  
  2414. @fix_it            lda        [scsi_zp0]
  2415.                 inc        a
  2416.                 inc        a
  2417.                 cmp        #$31
  2418.                 blt        @set_new_len
  2419.  
  2420.                 lda        #$31
  2421. @set_new_len    sta        [scsi_zp0]
  2422.  
  2423. @len_ok            tay
  2424. @name_loop        lda        [scsi_zp0],y
  2425.                 inc        a
  2426.  
  2427.                 cmp        #'1'
  2428.                 blt        @force_zero
  2429.  
  2430.                 cmp        #'9'+1
  2431.                 blt        @update
  2432.  
  2433. @force_zero        lda        #'0'
  2434.                 dex
  2435. @update            sta        [scsi_zp0],y
  2436.                 dey
  2437.                 dex
  2438.                 beq        @name_loop
  2439.  
  2440.                 longmx
  2441.  
  2442.                 rts
  2443.  
  2444.                 ENDP
  2445.  
  2446.                 EJECT
  2447.  
  2448. ;____DIB_Support_____
  2449. ;*******************************************************
  2450. ;
  2451. ;    This call is used to determine if the current DIB is
  2452. ;    the first device.  This routine will return true
  2453. ;    (with the carry clear) if the device is unlinked or,
  2454. ;    if linked, then it will return true if this is the
  2455. ;    head device.
  2456. ;
  2457. ;    Inputs:        Acc            =    Unspecified
  2458. ;                Y register    =    Unspecified
  2459. ;                X register    =    Unspecified
  2460. ;                P register    =    0=M=X=e
  2461. ;                Direct Page    =    Ours
  2462. ;                Data Bank    =    Ours
  2463. ;
  2464. ;    Outputs:    Acc            =    Unspecified
  2465. ;                Y register    =    Unspecified
  2466. ;                X register    =    Unspecified
  2467. ;                P register    =    0=M=X=e
  2468. ;                Direct Page    =    Ours
  2469. ;                Data Bank    =    Ours
  2470. ;
  2471. ;    Errors:        Carry set if Unit is not the first
  2472. ;                device or it's equivelent.
  2473. ;
  2474. ;*******************************************************
  2475.  
  2476.                 EXPORT    chk_first_dvc
  2477. chk_first_dvc    PROC
  2478.  
  2479. ;-------------------------------------------------------------------------------
  2480.  
  2481.                 IF            part_suprt = true        THEN
  2482.  
  2483.                                     ;
  2484.                                     ; Check Linkes to see if single device.
  2485.                                     ;
  2486.                 ldy        #dib.headlnk
  2487.                 lda        [dib_ptr],y
  2488.                 bne        @check_devnum
  2489.                                     ;
  2490.                                     ; Head Link = 0.  Return True.
  2491.                                     ;
  2492. @true            clc
  2493.                 rts
  2494.                                     ;
  2495.                                     ; Check to see if the Device Number and
  2496.                                     ; Head Links are the same.  If not then
  2497.                                     ; we return false (carry set).
  2498.                                     ;
  2499. @check_devnum    ldy        #dib.devnum
  2500.                 cmp        [dib_ptr],y
  2501.                 beq        @true
  2502.                                     ;
  2503.                                     ; Return False.
  2504.                                     ;
  2505.                 sec
  2506.                 rts
  2507.  
  2508.                 ELSE
  2509.  
  2510. ;-------------------------------------------------------------------------------
  2511.  
  2512.                 lda        #null
  2513.                 clc
  2514.                 rts
  2515.  
  2516.                 ENDIF
  2517.  
  2518. ;-------------------------------------------------------------------------------
  2519.  
  2520.  
  2521.                 ENDP
  2522.  
  2523.                 EJECT
  2524.  
  2525. ;*******************************************************
  2526. ;
  2527. ;    This call checks to see if the other device tied to
  2528. ;    it are offline.  If they are then the carry will be
  2529. ;    clear on exit.  If this device is tied to any other
  2530. ;    device that is currently online, then the carry will
  2531. ;    be set on exit.
  2532. ;
  2533. ;    Inputs:        Acc            =    Unspecified
  2534. ;                Y register    =    Unspecified
  2535. ;                X register    =    Unspecified
  2536. ;                P register    =    0=M=X=e
  2537. ;                Direct Page    =    Ours
  2538. ;                Data Bank    =    Ours
  2539. ;
  2540. ;    Outputs:    Acc            =    Unspecified
  2541. ;                Y register    =    Unspecified
  2542. ;                X register    =    Unspecified
  2543. ;                P register    =    0=M=X=e
  2544. ;                Direct Page    =    Ours
  2545. ;                Data Bank    =    Ours
  2546. ;
  2547. ;    Errors:        Carry set if Unit is not the only
  2548. ;                device in this link that is still
  2549. ;                online.
  2550. ;
  2551. ;*******************************************************
  2552.  
  2553.                 EXPORT    chk_lnk_offline
  2554. chk_lnk_offline    PROC
  2555.  
  2556. ;-------------------------------------------------------------------------------
  2557.  
  2558.                 IF            part_suprt = true        THEN
  2559.  
  2560.                                     ;
  2561.                                     ; Get the Head Pointer. Check for null.
  2562.                                     ;
  2563.                 clc
  2564.                 ldy        #dib.headptr
  2565.                 lda        [dib_ptr],y
  2566.                 sta        <scsi_zp6
  2567.                 beq        @over_0
  2568.                 sec
  2569. @over_0            ldy        #dib.headptr+2
  2570.                 lda        [dib_ptr],y
  2571.                 sta        <scsi_zp6+2
  2572.                                     ;
  2573.                                     ; Check if â‰  null.
  2574.                                     ;
  2575.                 bne        @check_it_loop
  2576.                 bcs        @check_it_loop
  2577.                                     ;
  2578.                                     ; It was null.  This may be the head
  2579.                                     ; of the link. Check it out.
  2580.                                     ;
  2581.                 ldy        #dib.fdvcptr
  2582.                 lda        [dib_ptr],y
  2583.                 ldy        #dib.fdvcptr+2
  2584.                 ora        [dib_ptr],y
  2585.                 beq        @no_link    ;No. Return to the caller with the carry clear.
  2586.                                     ;
  2587.                                     ; Yes. This was the head of the link.
  2588.                                     ; Set our pointer to this DIB.
  2589.                                     ;
  2590.                 lda        <dib_ptr
  2591.                 sta        <scsi_zp6
  2592.                 lda        <dib_ptr+2
  2593.                 sta        <scsi_zp6+2
  2594.                                     ;
  2595.                                     ; At this point, 'scsi_zp6' points to the
  2596.                                     ; head of the link.  Now walk the links
  2597.                                     ; checking for online.  If a device is
  2598.                                     ; online we will need to check if it is the
  2599.                                     ; callers device. if so, then we will
  2600.                                     ; continue the search.  If not, we will then
  2601.                                     ; exit with the carry set.
  2602.                                     ;
  2603. @check_it_loop    ldy        #dib.dvcflag
  2604.  
  2605.                 lda        [scsi_zp6],y
  2606.                 and        #dvc_online        ;Is it online?
  2607.                 beq        @not_online        ;No.
  2608.  
  2609.                 lda        [scsi_zp6],y    ;Yes.  Maybe.  Check hard offline
  2610.                 and        #dvc_hardofl    ;Is it hard offline?
  2611.                 bne        @not_online        ;Yes.
  2612.  
  2613.                 lda        <scsi_zp6+2    ;Is it the caller device?
  2614.                 cmp        <dib_ptr+2
  2615.                 bne        @linked        ;No.
  2616.                 lda        <scsi_zp6
  2617.                 cmp        <dib_ptr
  2618.                 bne        @linked        ;No.
  2619.                                     ;
  2620.                                     ; Point to next device.
  2621.                                     ;
  2622. @not_online        clc
  2623.                 ldy        #dib.fdvcptr
  2624.                 lda        [scsi_zp6],y
  2625.                 tax
  2626.                 beq        @over_2
  2627.                 sec
  2628. @over_2            ldy        #dib.fdvcptr+2
  2629.                 lda        [scsi_zp6],y
  2630.                 bne        @save_it
  2631.                 bcc        @no_link
  2632. @save_it        sta        <scsi_zp6+2
  2633.                 stx        <scsi_zp6
  2634.  
  2635.                 bra        @check_it_loop
  2636.                 
  2637.                                     ;
  2638.                                     ; Only device online.
  2639.                                     ;
  2640. @no_link        clc
  2641.                 rts
  2642.                                     ;
  2643.                                     ; Not the only device online.
  2644.                                     ;
  2645. @linked            sec
  2646.                 rts
  2647.  
  2648.                 ELSE
  2649.  
  2650. ;-------------------------------------------------------------------------------
  2651.  
  2652.                 lda        #null
  2653.                 clc
  2654.                 rts
  2655.  
  2656.                 ENDIF
  2657.  
  2658. ;-------------------------------------------------------------------------------
  2659.  
  2660.  
  2661.                 ENDP
  2662.  
  2663.                 EJECT
  2664.  
  2665. ;*******************************************************
  2666. ;
  2667. ;    'wake_me_up'
  2668. ;
  2669. ;    This call walks the DIBs, slaps them in the face and
  2670. ;    pours cold water on them.  It seems that they have
  2671. ;    been sleeping while P8 was running.
  2672. ;
  2673. ;                !!!! WAAAAAAAAKE  UUUUUUUP !!!!
  2674. ;
  2675. ;    Inputs:        Acc            =    Unspecified
  2676. ;                Y register    =    Unspecified
  2677. ;                X register    =    Unspecified
  2678. ;                P register    =    0=M=X=e
  2679. ;                Direct Page    =    Ours
  2680. ;                Data Bank    =    Ours
  2681. ;
  2682. ;    Outputs:    Acc            =    Unspecified
  2683. ;                Y register    =    Unspecified
  2684. ;                X register    =    Unspecified
  2685. ;                P register    =    0=M=X=e
  2686. ;                Direct Page    =    Ours
  2687. ;                Data Bank    =    Ours
  2688. ;
  2689. ;    Errors:        None.
  2690. ;
  2691. ;*******************************************************
  2692.  
  2693.                 EXPORT    wake_me_up
  2694. wake_me_up        PROC
  2695.  
  2696. ;-------------------------------------------------------------------------------
  2697.  
  2698.                 IF        warm_ss_suprt = true        THEN
  2699.  
  2700.                                             ;
  2701.                                             ; Start with the first DIB after
  2702.                                             ; the default DIB
  2703.                                             ;
  2704.                 lda        |default_dib
  2705.                 sta        <first_dib
  2706.                 sta        <next_dib
  2707.                 lda        |default_dib+2
  2708.                 sta        <first_dib+2
  2709.                 sta        <next_dib+2
  2710.                                             ;
  2711.                                             ; Is he asleep?
  2712.                                             ;
  2713. @check_it_loop    ldy        #dib.dvcflag
  2714.                 lda        [next_dib],y
  2715.                 tax
  2716.                 and        #relaxing
  2717.                 beq        @next_dib            ;No he is not asleep
  2718.                                             ;
  2719.                                             ; Yes he is!  Is he also Hard
  2720.                                             ; Offline?
  2721.                                             ;
  2722.                 txa
  2723.                 and        #dvc_hardofl
  2724.                 beq        @not_hardofl        ;No.  Wake him up all the way then.
  2725.  
  2726.                 txa                            ;Yes.  Only Clear Sleep Bit.
  2727.                 and        #relaxing--\        ;Don't set online.
  2728.                         $ffff
  2729.                 sta        [next_dib],y
  2730.  
  2731.                 bra        @next_dib
  2732.                                             ;
  2733.                                             ; Yes he is, wake him up.
  2734.                                             ;
  2735. @not_hardofl    txa
  2736.                 and        #relaxing--\
  2737.                         $ffff
  2738.                 ora        #dvc_online
  2739.                 sta        [next_dib],y
  2740.                                             ;
  2741.                                             ; Advance to the next one
  2742.                                             ;
  2743. @next_dib        clc
  2744.                 ldy        #dib.linkptr
  2745.                 lda        [next_dib],y
  2746.                 tax
  2747.                 beq        @over_0
  2748.                 sec
  2749. @over_0            ldy        #dib.linkptr+2
  2750.                 lda        [next_dib],y
  2751.                 sta        <next_dib+2
  2752.                 stx        <next_dib
  2753.                                             ;
  2754.                                             ; Check if â‰  null.
  2755.                                             ;
  2756.                 bne        @check_it_loop
  2757.                 bcs        @check_it_loop
  2758.                                             ;
  2759.                                             ; That was the last one.
  2760.                                             ;
  2761.                                             ; By default of the branches above,
  2762.                                             ; the Acc. = 0 and the carry is clear.
  2763.                                             ;
  2764.                 rts
  2765.  
  2766. ;-------------------------------------------------------------------------------
  2767.  
  2768.                  ELSE
  2769.  
  2770. ;-------------------------------------------------------------------------------
  2771.  
  2772.                 clc
  2773.                 rts
  2774.  
  2775.                  ENDIF
  2776.  
  2777. ;-------------------------------------------------------------------------------
  2778.  
  2779.  
  2780.                 ENDP
  2781.  
  2782.                 EJECT
  2783.  
  2784. ;*******************************************************
  2785. ;
  2786. ;    'fix_unit_1'
  2787. ;
  2788. ;    This call walks the DIBs, ensuring that unit 1 is
  2789. ;    the first ProDOS Partition on the disk..
  2790. ;
  2791. ;    Inputs:        Acc            =    Unspecified
  2792. ;                Y register    =    Unspecified
  2793. ;                X register    =    Unspecified
  2794. ;                P register    =    0=M=X=e
  2795. ;                Direct Page    =    Ours
  2796. ;                Data Bank    =    Ours
  2797. ;
  2798. ;    Outputs:    Acc            =    Unspecified
  2799. ;                Y register    =    Unspecified
  2800. ;                X register    =    Unspecified
  2801. ;                P register    =    0=M=X=e
  2802. ;                Direct Page    =    Ours
  2803. ;                Data Bank    =    Ours
  2804. ;
  2805. ;    Errors:        None.
  2806. ;
  2807. ;*******************************************************
  2808.  
  2809.                 EXPORT    fix_unit_1
  2810. fix_unit_1        PROC
  2811.  
  2812. ;-------------------------------------------------------------------------------
  2813.  
  2814.                 IF        part_suprt = true        THEN
  2815.  
  2816.                                         ;
  2817.                                         ; Check the pdos Bit for the Unit number 1.
  2818.                                         ; This may or may not be the head device.
  2819.                                         ;
  2820.                 ldy        #dib.headptr
  2821.                 lda        [dib_ptr],y
  2822.                 sta        <scsi_zp0
  2823.                 ldy        #dib.headptr+2
  2824.                 lda        [dib_ptr],y
  2825.                 sta        <scsi_zp0+2
  2826.                 ora        <scsi_zp0        ;Are we at the Head Now?
  2827.                 bne        @check_it        ;No.
  2828.                                         ;
  2829.                                         ; We were already at the head.  Set pointer
  2830.                                         ; to this DIB before going on.
  2831.                                         ;
  2832.                 lda        <dib_ptr
  2833.                 sta        <scsi_zp0
  2834.                 lda        <dib_ptr+2
  2835.                 sta        <scsi_zp0+2
  2836.                                         ;
  2837.                                         ; Is this unit number 1?
  2838.                                         ;
  2839. @check_it        ldy        #dib.unitnum
  2840.                 lda        [scsi_zp0],y
  2841.                 and        #max_p_mask
  2842.                 beq        @unit_1            ;Yes.
  2843.                                         ;
  2844.                                         ; No.  It's not unit number one.  Check the
  2845.                                         ; next DIB in the link if it is non-zero.
  2846.                                         ;
  2847.                 clc
  2848.                 ldy        #dib.fdvcptr
  2849.                 lda        [scsi_zp0],y
  2850.                 tax
  2851.  
  2852.                 beq        @over_sec
  2853.                 sec
  2854.  
  2855. @over_sec        ldy        #dib.fdvcptr+2
  2856.                 lda        [scsi_zp0],y
  2857.  
  2858.                 bne        @set_ptr
  2859.                 bcc        @out
  2860.  
  2861. @set_ptr        sta        <scsi_zp0+2
  2862.                 stx        <scsi_zp0
  2863.                 bra        @check_it
  2864.                                         ;
  2865.                                         ; This is unit 1.  Is it a ProDOS Partition?
  2866.                                         ;
  2867. @unit_1            ldy        #dib.dvcflag
  2868.                 lda        [scsi_zp0],y
  2869.                 and        #pdos_part
  2870.                 bne        @out            ;It's ProDOS, Get out of here.
  2871.                                         ;
  2872.                                         ; We're out of here.
  2873.                                         ;
  2874. @out            clc
  2875.                 rts
  2876.  
  2877. ;-------------------------------------------------------------------------------
  2878.  
  2879.                  ELSE                    ;part_suprt = true
  2880.  
  2881. ;-------------------------------------------------------------------------------
  2882.  
  2883.                 clc
  2884.                 rts
  2885.  
  2886.                  ENDIF                    ;part_suprt = true
  2887.  
  2888. ;-------------------------------------------------------------------------------
  2889.  
  2890.  
  2891.                 ENDP                    ;fix_unit_1
  2892.  
  2893.                 EJECT
  2894.  
  2895. ;*******************************************************
  2896. ;
  2897. ;    ADD_DIB_PTR
  2898. ;
  2899. ;    This routine adds a pointer to a list of dibs to be
  2900. ;    installed by the 'POST_DRIVER_INSTALL' System
  2901. ;    Service call.  Refer to the System Service ERS for
  2902. ;    details of how this works.
  2903. ;
  2904. ;    Inputs:        Acc                =    Unspecified
  2905. ;                Y register        =    High word of dib ptr
  2906. ;                X register        =    Low word of dib ptr
  2907. ;                P register        =    0=M=X=e
  2908. ;                Direct Page        =    Ours
  2909. ;                Data Bank        =    Ours
  2910. ;
  2911. ;    Outputs:    <DIB_PTR        =    Empty DIB if found
  2912. ;                Acc                =    Unspecified
  2913. ;                Y register        =    Unspecified
  2914. ;                X register        =    Unspecified
  2915. ;                P register        =    0=M=X=e
  2916. ;                Direct Page        =    Ours
  2917. ;                Data Bank        =    Ours
  2918. ;
  2919. ;    Errors:        None
  2920. ;
  2921. ;*******************************************************
  2922.  
  2923.                 EXPORT    add_dib_ptr
  2924. add_dib_ptr        PROC
  2925.  
  2926. ;-------------------------------------------------------------------------------
  2927.  
  2928.                 IF            part_suprt = true        THEN
  2929.  
  2930.                                         ;
  2931.                                         ; Check to see if this has an overide
  2932.                                         ; placed on it.
  2933.                                         ;
  2934.                 lda        |dpi_overide
  2935.                 bmi        @exit            ;Yes.
  2936.                                         ;
  2937.                                         ; Is this the first time that this has been
  2938.                                         ; called for this session.  Only the
  2939.                                         ; do_post_install can clear this flag.
  2940.                                         ;
  2941.                 lda        |new_list
  2942.                 beq        @start_over        ; Acc. = 0
  2943.                                         ;
  2944.                                         ; Inc the count of new devices to be started.
  2945.                                         ;
  2946.                 lda        |new_dib_cnt
  2947. @start_over        pha
  2948.                 inc        a
  2949.                 sta        |new_dib_cnt
  2950.                 sta        |new_list
  2951.                 pla
  2952.                                                 ;
  2953.                                                 ; Calculate offset for next ptr.
  2954.                                                 ;
  2955.                 asl        a
  2956.                 asl        a
  2957.                 pha
  2958.                 txa
  2959.                 plx
  2960.                 sta        |new_dib_list,x            ;Place Ptr in list
  2961.                 sta        <scsi_zp0                ;and on zero page.
  2962.  
  2963.                 tya
  2964.                 sta        |new_dib_list+2,x        ;Place Ptr in list
  2965.                 sta        <scsi_zp0+2                ;and on zero page.
  2966.  
  2967.                 ldy        #dib.dvcflag
  2968.                 lda        [scsi_zp0],y
  2969.                 ora        #cold_dib                ;New DIB.  Do Cold Start.
  2970.                 sta        [scsi_zp0],y
  2971.  
  2972. @exit            clc
  2973.                 rts
  2974.  
  2975.                 ELSE
  2976.  
  2977. ;-------------------------------------------------------------------------------
  2978.  
  2979.                 lda        #null
  2980.                 clc
  2981.                 rts
  2982.  
  2983.                 ENDIF
  2984.  
  2985. ;-------------------------------------------------------------------------------
  2986.  
  2987.                 ENDP
  2988.  
  2989.                 EJECT
  2990.  
  2991. ;*******************************************************
  2992. ;
  2993. ;    DO_POST_INSTALL
  2994. ;
  2995. ;    This routine calls the 'POST_DRIVER_INSTALL' System
  2996. ;    Service call.  Refer to the System Service ERS for
  2997. ;    details of how this works.
  2998. ;
  2999. ;    Inputs:        Acc                =    Unspecified
  3000. ;                Y register        =    High word of dib ptr
  3001. ;                X register        =    Low word of dib ptr
  3002. ;                P register        =    0=M=X=e
  3003. ;                Direct Page        =    Ours
  3004. ;                Data Bank        =    Ours
  3005. ;
  3006. ;    Outputs:    <DIB_PTR        =    Empty DIB if found
  3007. ;                Acc                =    Unspecified
  3008. ;                Y register        =    Unspecified
  3009. ;                X register        =    Unspecified
  3010. ;                P register        =    0=M=X=e
  3011. ;                Direct Page        =    Ours
  3012. ;                Data Bank        =    Ours
  3013. ;
  3014. ;    Errors:        None
  3015. ;
  3016. ;*******************************************************
  3017.  
  3018.                 EXPORT    do_post_install
  3019. do_post_install    PROC
  3020.  
  3021. ;-------------------------------------------------------------------------------
  3022.  
  3023.                 IF            part_suprt = true        THEN
  3024.  
  3025.                                         ;
  3026.                                         ; Check to see if this has an overide
  3027.                                         ; placed on it.
  3028.                                         ;
  3029.                 lda        |dpi_overide
  3030.                 bmi        @exit            ;Yes.
  3031.                                         ;
  3032.                                         ; Clear flag indicating that the call was
  3033.                                         ; sent.
  3034.                                         ;
  3035.                 stz        |pdi_flag
  3036.                 stz        |new_list
  3037.                                         ;
  3038.                                         ; Check the count of new devices to be
  3039.                                         ; started.
  3040.                                         ;
  3041.                 lda        |new_dib_cnt
  3042.                 beq        @exit
  3043.                                         ;
  3044.                                         ; Make the call
  3045.                                         ;
  3046.                 lda        |gsos_dpage
  3047.                 tcd
  3048.                 ldx        #new_dib_cnt
  3049.                 ldy        #^new_dib_cnt
  3050.  
  3051.                 jsl        install_driver
  3052.                 pha
  3053.                 lda        |direct_page
  3054.                 tcd
  3055.                 pla
  3056.  
  3057.                 bcs        @exit
  3058.                 dec        |pdi_flag
  3059.                 
  3060. @exit            clc
  3061.                 rts
  3062.  
  3063.                 ELSE
  3064.  
  3065. ;-------------------------------------------------------------------------------
  3066.  
  3067.                 lda        #null
  3068.                 clc
  3069.                 rts
  3070.  
  3071.                 ENDIF
  3072.  
  3073. ;-------------------------------------------------------------------------------
  3074.  
  3075.                 ENDP
  3076.  
  3077.                 EJECT
  3078.  
  3079. ;____Part_Support____
  3080.  
  3081. ;-------------------------------------------------------------------------------
  3082.  
  3083.                 IF            part_suprt = true        THEN
  3084.  
  3085. ;*******************************************************
  3086. ;
  3087. ;    READ_PM_BLK
  3088. ;
  3089. ;    
  3090. ;
  3091. ;    Inputs:        Acc            =    Unspecified
  3092. ;                Y register    =    Unspecified
  3093. ;                X register    =    Unspecified
  3094. ;                P register    =    0=M=X=e
  3095. ;                Direct Page    =    Ours
  3096. ;                Data Bank    =    Ours
  3097. ;
  3098. ;    Outputs:    Acc            =    Unspecified
  3099. ;                Y register    =    Unspecified
  3100. ;                X register    =    Unspecified
  3101. ;                P register    =    0=M=X=e
  3102. ;                Direct Page    =    Ours
  3103. ;                Data Bank    =    Ours
  3104. ;
  3105. ;    Errors:        Carry set if operation could not be
  3106. ;                completed.  Out of memory for example.
  3107. ;
  3108. ;*******************************************************
  3109.  
  3110.                 EXPORT    read_pm_blk
  3111. read_pm_blk        PROC
  3112.                                         ;
  3113.                                         ; Tell the Main Driver where
  3114.                                         ; our command structure resides.
  3115.                                         ;
  3116.                 lda        #@read_part
  3117.                 sta        <scsi_mdrvr
  3118.                 lda        #^@read_part
  3119.                 sta        <scsi_mdrvr+2
  3120.                                         ;
  3121.                                         ; And our buffer
  3122.                                         ;
  3123.                 lda        #internal_buff
  3124.                 sta        <buff_ptr
  3125.                 lda        #^internal_buff
  3126.                 sta        <buff_ptr+2
  3127.                                         ;
  3128.                                         ; Was this from the STARTUP Call?
  3129.                                         ;
  3130.                 bit        |rebuild
  3131.                 bmi        @over            ;No.
  3132.                                         ;
  3133.                                         ; Yes, then stuff the pointer to
  3134.                                         ; the dib that we are building into
  3135.                                         ; the Direct Page locations.  The
  3136.                                         ; main driver will use this to build
  3137.                                         ; the SCSI READ BLOCK Command that
  3138.                                         ; we will issue.
  3139.                                         ;
  3140.                 lda        <next_dib
  3141.                 sta        <dib_ptr
  3142.                 lda        <next_dib+2
  3143.                 sta        <dib_ptr+2
  3144.                                         ;
  3145.                                         ; And our length from the DIB's
  3146.                                         ; Block Size value
  3147.                                         ;
  3148. @over            lda        #block_size
  3149.                 sta        <rqst_cnt
  3150.                 lda        #^block_size
  3151.                 sta        <rqst_cnt+2
  3152.                                         ;
  3153.                                         ; Set block to read for the next
  3154.                                         ; partition map block.  This field
  3155.                                         ; is initialized to zero.  Because
  3156.                                         ; the first partition map block is
  3157.                                         ; on block 1, this will be initialized
  3158.                                         ; to zero and then blindly incremented
  3159.                                         ; until we are finished.
  3160.                                         ;
  3161.                                         ; *** This is High --> Low format ***
  3162.                                         ;
  3163.                 lda        |pm_blk_num
  3164.                 xba
  3165.                 inc        a
  3166.                 xba
  3167.                 sta        |pm_blk_num
  3168.                                         ;
  3169.                                         ; Set internal command flag
  3170.                                         ;
  3171.                 dec        |internal
  3172.                                         ;
  3173.                                         ; Set the Partition call flag
  3174.                                         ;
  3175.                 dec        |f_partition
  3176.                                         ;
  3177.                                         ; Set the Call Type and Issue the
  3178.                                         ; READ BLOCK Command.
  3179.                                         ;
  3180.                 lda        #scsit_stat
  3181.                 sta        |call_type
  3182.                                         ;
  3183.                                         ; Issue the call.
  3184.                                         ;
  3185.                 jsr        check_532_rw
  3186.  
  3187. @rts            rts
  3188.                                         ;
  3189.                                         ; Data for the READ BLOCK Command
  3190.                                         ;
  3191. @read_part        dc.b        $08
  3192.                 dc.b        null
  3193.                 EXPORT        pm_blk_num
  3194. pm_blk_num        dc.w        null
  3195.                 dcb.b        10,null
  3196.  
  3197.                 ENDP
  3198.  
  3199.                 EJECT
  3200.  
  3201. ;*******************************************************
  3202. ;
  3203. ;    CHK_MAP
  3204. ;
  3205. ;    This routine checks the validity of the partition
  3206. ;    map block currently loaded in the internal buffer.
  3207. ;    This need only be called once per device.  If the
  3208. ;    map is valid, then the carry will be clear.  The 'Z'
  3209. ;    flag will also be set if this is not the first time
  3210. ;    that this routine was called for this device.  If
  3211. ;    the carry is set, then the map was invalid and the
  3212. ;    block count at 'T_DVC_BLOCKS' has been placed in the
  3213. ;    DIB pointed to by 'DIB_PTR'.  The starting block will
  3214. ;    also have been set to null.
  3215. ;
  3216. ;    Inputs:        <DIB_PTR        =    DIB Location
  3217. ;                |T_DVC_BLOCKS    =    Total blocks for this device
  3218. ;                Acc                =    Unspecified
  3219. ;                Y register        =    Unspecified
  3220. ;                X register        =    Unspecified
  3221. ;                P register        =    0=M=X=e
  3222. ;                Direct Page        =    Ours
  3223. ;                Data Bank        =    Ours
  3224. ;
  3225. ;    Outputs:    Acc                =    Unspecified
  3226. ;                Y register        =    Unspecified
  3227. ;                X register        =    Unspecified
  3228. ;                P register        =    0=M=X=e
  3229. ;                                =    Z = 0 if routine called before
  3230. ;                                =    C = 1 if not a partition map
  3231. ;                Direct Page        =    Ours
  3232. ;                Data Bank        =    Ours
  3233. ;
  3234. ;    Errors:        Carry set if 'internal_buff does not
  3235. ;                contain a valid Partition map entry.
  3236. ;
  3237. ;*******************************************************
  3238.  
  3239.                 EXPORT    chk_map
  3240. chk_map            PROC
  3241.                                         ;
  3242.                                         ; Valid Partition Map?
  3243.                                         ;
  3244. @over_0            inc        |first_time        ;Don't need to do this but once.
  3245.                 bne        @clc            ;Already done if taken.
  3246.                 
  3247.                 lda        |pm.Sig\
  3248.                         +internal_buff
  3249.                 cmp        #Part_sig
  3250.                 bne        no_partition    ;No.
  3251.  
  3252. @clc            clc
  3253.                 rts
  3254.                                         ;
  3255.                                         ; We didn't have a valid partition
  3256.                                         ; map, so this device will be
  3257.                                         ; treated as a single non-partitioned
  3258.                                         ; device.
  3259.                                         ;
  3260.                 EXPORT    no_partition
  3261.  
  3262. no_partition    ldy        #dib.blkcnt
  3263.                 lda        |t_dvc_blocks
  3264.                 sta        [dib_ptr],y
  3265.                 ldy        #dib.blkcnt+2
  3266.                 lda        |t_dvc_blocks+2
  3267.                 sta        [dib_ptr],y
  3268.                 ldy        #dib.start_blk
  3269.                 lda        #null
  3270.                 sta        [dib_ptr],y
  3271.                 ldy        #dib.start_blk+2
  3272.                 sta        [dib_ptr],y
  3273.                                         ;
  3274.                                         ; Mark DIB as online and switched.
  3275.                                         ;
  3276.                 ldy        #dib.dvcflag
  3277.                 lda        [dib_ptr],y
  3278.                 and        #dvc_hardofl--\
  3279.                         $ffff
  3280.                 ora        #dvc_switch++\
  3281.                         dvc_online
  3282.                 sta        [dib_ptr],y
  3283.  
  3284.                 sec
  3285.                 rts
  3286.  
  3287.                 ENDP
  3288.  
  3289.                 EJECT
  3290.  
  3291. ;*******************************************************
  3292. ;
  3293. ;    'check_map_entry'
  3294. ;
  3295. ;    Check the Partition Map Entry currently loaded in
  3296. ;    the internal buffer.  If it is of type
  3297. ;    'Apple_partition_map', 'Apple_Free', or
  3298. ;    'Apple_Scratch', then this routine will return with
  3299. ;    the carry set.  Any other type will return with the
  3300. ;    carry clear.  In addition, 'Apple_ProDOS' will
  3301. ;    return with the overflow flag set.
  3302. ;
  3303. ;    Inputs:        Acc            =    Unspecified
  3304. ;                Y register    =    Unspecified
  3305. ;                X register    =    Unspecified
  3306. ;                P register    =    0=M=X=e
  3307. ;                Direct Page    =    Ours
  3308. ;                Data Bank    =    Ours
  3309. ;
  3310. ;    Outputs:    Acc            =    Unspecified
  3311. ;                Y register    =    Unspecified
  3312. ;                X register    =    Unspecified
  3313. ;                P register    =    0=M=X=e
  3314. ;                Direct Page    =    Ours
  3315. ;                Data Bank    =    Ours
  3316. ;
  3317. ;    Errors:        Carry set if Partition Map Entry is not
  3318. ;                for a valid Volume.  Overflow set if the
  3319. ;                Partition is a ProDOS Partition.
  3320. ;
  3321. ;*******************************************************
  3322.  
  3323.                 EXPORT    check_map_entry
  3324. check_map_entry    PROC
  3325.                                         ;
  3326.                                         ; This routine runs in
  3327.                                         ; 8 bit m and x only.
  3328.                                         ;
  3329.                 short
  3330.                                         ;
  3331.                                         ; Is it ProDOS?
  3332.                                         ;
  3333.                 ldx        #@p_map-@prodos-2
  3334.                 ldy        #null
  3335.  
  3336. @loop            lda        |pm.PartType\
  3337.                         +internal_buff,y
  3338.                 beq        @over_0            ;Yes or null.  Either way we do the rest.
  3339.                 cmp        @prodos,y
  3340.                 beq        @next
  3341.                 eor        #'A'--'a'
  3342.                 cmp        @prodos,y
  3343.                 bne        @over_0            ;No.  Continue on.
  3344. @next            iny
  3345.                 dex
  3346.                 bpl        @loop
  3347.                 brl        @pdos_part        ;Skip over 8 bit code area to 16 bit area.
  3348.                                         ;
  3349.                                         ; Is it the Partition Map?
  3350.                                         ;
  3351. @over_0            ldx        #32-1
  3352.                 ldy        #null
  3353.  
  3354. @loop_0            lda        |pm.PartType\
  3355.                         +internal_buff,y
  3356.                 beq        @skip            ;Yes or null.  Either way we skip it.
  3357.                 cmp        @p_map,y
  3358.                 beq        @next_0
  3359.                 eor        #'A'--'a'
  3360.                 cmp        @p_map,y
  3361.                 bne        @over_1            ;No.  Continue on.
  3362. @next_0            iny
  3363.                 dex
  3364.                 bpl        @loop_0
  3365.                 bra        @skip            ;Yes. Skip it.
  3366.                                         ;
  3367.                                         ; Is it a FREE Partition?
  3368.                                         ;
  3369. @over_1            ldx        #32-1
  3370.                 ldy        #null
  3371.  
  3372. @loop_1            lda        |pm.PartType\
  3373.                         +internal_buff,y
  3374.                 beq        @skip            ;Yes or null.  Either way we skip it.
  3375.                 cmp        @free,y
  3376.                 beq        @next_1
  3377.                 eor        #'A'--'a'
  3378.                 cmp        @free,y
  3379.                 bne        @over_2            ;No.  Continue on.
  3380. @next_1            iny
  3381.                 dex
  3382.                 bpl        @loop_1
  3383.                 bra        @skip            ;Yes. Skip it.
  3384.                                         ;
  3385.                                         ; Is it a SCRATCH Partition?
  3386.                                         ;
  3387. @over_2            ldx        #32-1
  3388.                 ldy        #null
  3389.  
  3390. @loop_2            lda        |pm.PartType\
  3391.                         +internal_buff,y
  3392.                 beq        @skip            ;Yes or null.  Either way we skip it.
  3393.                 cmp        @scratch,y
  3394.                 beq        @next_2
  3395.                 eor        #'A'--'a'
  3396.                 cmp        @scratch,y
  3397.                 bne        @over_3            ;No.  Continue on.
  3398. @next_2            iny
  3399.                 dex
  3400.                 bpl        @loop_2
  3401.                                         ;
  3402.                                         ; At this point the Current Partition
  3403.                                         ; Type matched one of the three types
  3404.                                         ; checked for.  Exit with the carry
  3405.                                         ; set.
  3406.                                         ;
  3407. @skip            longmx
  3408.                 sec
  3409.                 rts
  3410.                                         ;
  3411.                                         ; At this point the Current Partition
  3412.                                         ; Type did not match one of the three
  3413.                                         ; types checked for and it was not a
  3414.                                         ; ProDOS Partition..  Exit with the
  3415.                                         ; Carry and Overflow bits clear.
  3416.                                         ;
  3417. @over_3            longmx
  3418.                 clc
  3419.                 clv
  3420.                 rts
  3421.                                         ;
  3422.                                         ; At this point the Current Partition
  3423.                                         ; Type is a ProDOS Partition.  Exit with
  3424.                                         ; the Carry clear and Overflow set.
  3425.                                         ;
  3426. @pdos_part        longmx
  3427.                 clc
  3428.                 sep        #%01000000        ;Set the v flag
  3429.                 rts
  3430.                                         ;
  3431.                                         ; Inactive Partion Types to check for.
  3432.                                         ;
  3433.                 STRING        ASIS
  3434.  
  3435. @prodos            dc.b        'Apple_ProDOS'
  3436.                 dc.b        $00
  3437. @p_map            dc.b        'Apple_partition_map'    
  3438.                 dc.b        $00
  3439. @free            dc.b        'Apple_Free'
  3440.                 dc.b        $00
  3441. @scratch        dc.b        'Apple_Scratch'
  3442.                 dc.b        $00
  3443.  
  3444.                 STRING        PASCAL
  3445.  
  3446.                 ENDP
  3447.  
  3448.                 EJECT
  3449.  
  3450.                 ELSE                    ;part_suprt = true
  3451.  
  3452. ;-------------------------------------------------------------------------------
  3453.  
  3454.                 EXPORT        read_pm_blk
  3455. read_pm_blk        PROC
  3456.  
  3457.                 EXPORT        check_map_entry
  3458. check_map_entry
  3459.                 lda        #null
  3460.                 clc
  3461.                 clv
  3462.                 rts
  3463.  
  3464.  
  3465.                 EXPORT        pm_blk_num
  3466. pm_blk_num        dc.w    null
  3467.  
  3468.                 EXPORT        chk_map
  3469. chk_map
  3470.                                         ;
  3471.                                         ; We can't have a valid partition
  3472.                                         ; map, so this device will be
  3473.                                         ; treated as a single non-partitioned
  3474.                                         ; device.
  3475.                                         ;
  3476.                 EXPORT    no_partition
  3477.  
  3478. no_partition    ldy        #dib.blkcnt
  3479.                 lda        |t_dvc_blocks
  3480.                 sta        [dib_ptr],y
  3481.                 ldy        #dib.blkcnt+2
  3482.                 lda        |t_dvc_blocks+2
  3483.                 sta        [dib_ptr],y
  3484.                 ldy        #dib.start_blk
  3485.                 lda        #null
  3486.                 sta        [dib_ptr],y
  3487.                 ldy        #dib.start_blk+2
  3488.                 sta        [dib_ptr],y
  3489.                                         ;
  3490.                                         ; Mark DIB as online and switched.
  3491.                                         ;
  3492.                 ldy        #dib.dvcflag
  3493.                 lda        [dib_ptr],y
  3494.                 and        #dvc_hardofl--\
  3495.                         $ffff
  3496.                 ora        #dvc_switch++\
  3497.                         dvc_online
  3498.                 sta        [dib_ptr],y
  3499.  
  3500.                 sec
  3501.                 rts
  3502.  
  3503.                 ENDIF                    ;part_suprt = true
  3504.  
  3505. ;-------------------------------------------------------------------------------
  3506.  
  3507. ;____Cache_Suport____
  3508.  
  3509. ;-------------------------------------------------------------------------------
  3510.  
  3511.                 IF            cache_blks = true    THEN
  3512.  
  3513. ;*******************************************************
  3514. ;
  3515. ;    'r_all_in_cache'
  3516. ;
  3517. ;    This routine is used to check if the entire
  3518. ;    requested block count is in the cache.  This routine
  3519. ;    will check each block individually, incrementing the
  3520. ;    block count and subtracting the block size from the
  3521. ;    request count until either a block is found that is
  3522. ;    not in the cache (Exit Carry Set) or request count
  3523. ;    has been exausted (Exit Carry Clear).
  3524. ;
  3525. ;    On entry this routine clears some values to indicate
  3526. ;    it's starting point for this call.  As it goes
  3527. ;    throughthe cache looking for blocks, it will fetch
  3528. ;    the block from the cache and advance the starting
  3529. ;    point.  What this does is eliminate double searches
  3530. ;    throughthe cache and if a read is needed, these
  3531. ;    blocks will not have to be transfered.  When this
  3532. ;    routine exits, the caller will think that the first
  3533. ;    block that we found that was not in the cache was
  3534. ;    the first block requested.  For this reason, any
  3535. ;    code that uses this call will need to preserve those
  3536. ;    values so that they can be restored on exit.
  3537. ;
  3538. ;    If we receive a Read Call for 256 blocks and the
  3539. ;    first 128 are in the cache, then we don't want to
  3540. ;    re-read them, and we don't want to do a find again
  3541. ;    later when we fetch them.  let's fetch them now and
  3542. ;    advance our pointers.
  3543. ;
  3544. ;    Inputs:        Acc            =    Unspecified
  3545. ;                Y register    =    Unspecified
  3546. ;                X register    =    Unspecified
  3547. ;                P register    =    0=M=X=e
  3548. ;                Direct Page    =    Ours
  3549. ;                <buff_ptr    =    Original Starting Buffer
  3550. ;                <rqst_cnt    =    Original Request Count
  3551. ;                <block_num    =    Original Starting Block
  3552. ;                Data Bank    =    Ours
  3553. ;
  3554. ;    Outputs:    Acc            =    Unspecified
  3555. ;                Y register    =    Unspecified
  3556. ;                X register    =    Unspecified
  3557. ;                P register    =    0=M=X=e
  3558. ;                Direct Page    =    Ours
  3559. ;                <buff_ptr    =    New Starting Buffer
  3560. ;                <rqst_cnt    =    New Request Count
  3561. ;                <block_num    =    New Starting Block
  3562. ;                Data Bank    =    Ours
  3563. ;
  3564. ;    Errors:        Acc = 0 and Carry set if 1 or more
  3565. ;                blocks of the request are not in the
  3566. ;                cache.
  3567. ;
  3568. ;                Acc <> 0 if any other error occurs.
  3569. ;                Error code is in Acc.
  3570. ;
  3571. ;*******************************************************
  3572.  
  3573.                 EXPORT    r_all_in_cache
  3574. r_all_in_cache    PROC
  3575.                                         ;
  3576.                                         ; Switch Direct Pages.
  3577.                                         ;
  3578.                 lda        |gsos_dpage
  3579.                 tcd
  3580.                                         ;
  3581.                                         ; Get the requested count and devide
  3582.                                         ; by block size to get the loop counter.
  3583.                                         ; If Count = 0, then exit.
  3584.                                         ;
  3585.                 lda        <rqst_cnt
  3586.                 sta        |divend
  3587.                 lda        <rqst_cnt+2
  3588.                 sta        |divend+2
  3589.  
  3590.                 ora        <rqst_cnt
  3591.                 bne        @continue
  3592.  
  3593.                 lda        |direct_page
  3594.                 tcd
  3595.                 lda        #null
  3596.                 clc
  3597. @rts            rts
  3598.  
  3599.                                         ;
  3600.                                         ; Call divide routine.
  3601.                                         ;
  3602. @continue        lda        <blk_size
  3603.                 sta        |divsor
  3604.  
  3605.                 jsr        divide
  3606.                 bcc        @over_divide
  3607.  
  3608.                 lda        |direct_page
  3609.                 tcd
  3610.  
  3611.                 lda        #drvr_bad_cnt    ;non-integral rqst count.
  3612.                 sec
  3613.                 rts
  3614.                                         ;
  3615.                                         ; Count = count -1.  This way we can
  3616.                                         ; use a BMI to exit with.
  3617.                                         ;
  3618. @over_divide    lda        |result+2
  3619.                 sta        @blk_cnt+2
  3620.                 lda        |result
  3621.                 sta        @blk_cnt
  3622.                 bne        @over_dec_high
  3623.                 dec        @blk_cnt+2
  3624. @over_dec_high    dec        @blk_cnt
  3625.                                         ;
  3626.                                         ; Setup is now completed.  Now we start to
  3627.                                         ; check to see if the blocks are in the
  3628.                                         ; cache.
  3629.                                         ;
  3630. @chk_blk_loop    sec                        ;return error if not in cache. Don't add.
  3631.                 jsr        |get_from_cache
  3632.                 bcc        @found
  3633.                 lda        #null            ;Not there.  Clear the Acc. and Exit.
  3634.                 bra        @restore
  3635.                                         ;
  3636.                                         ; Are there any more to do?
  3637.                                         ;
  3638. @found            lda        @blk_cnt
  3639.                 bne        @over_dec
  3640.                 dec        @blk_cnt+2
  3641.                 bpl        @over_dec
  3642.                                         ;
  3643.                                         ; No. Count is exausted.
  3644.                                         ;
  3645.                 lda        #null
  3646.                 clc
  3647.                 bra        @restore
  3648.                                         ;
  3649.                                         ; Yes. Finish the DEC and update the
  3650.                                         ; Buffer Pointer, Request Count, and
  3651.                                         ; the Block Number.
  3652.                                         ;
  3653. @over_dec        dec        @blk_cnt
  3654.  
  3655.                 clc                        ;Bump Buffer Pointer
  3656.                 lda        <buff_ptr
  3657.                 adc        <blk_size
  3658.                 sta        <buff_ptr
  3659.                 lda        <buff_ptr+2
  3660.                 adc        #null
  3661.                 sta        <buff_ptr+2
  3662.  
  3663.                 sec                        ;Back off Request Count
  3664.                 lda        <rqst_cnt
  3665.                 sbc        <blk_size
  3666.                 sta        <rqst_cnt
  3667.                 lda        <rqst_cnt+2
  3668.                 sbc        #null
  3669.                 sta        <rqst_cnt+2
  3670.  
  3671.                 inc        <block_num        ;Inc the Block Number
  3672.                 bne        @chk_blk_loop
  3673.                 inc        <block_num+2
  3674.                 bra        @chk_blk_loop
  3675.                                         ;
  3676.                                         ; We are finished.  We don't need to
  3677.                                         ; know if we were succesfull.  We only
  3678.                                         ; need to restore the state of the
  3679.                                         ; corrupted direct page values while
  3680.                                         ; preserving the Acc. and Carry bit.
  3681.                                         ;
  3682. @restore        pha
  3683.                 php
  3684.  
  3685.                 ldx        |direct_page
  3686.  
  3687.                 lda        <buff_ptr
  3688.                 sta        >buff_ptr,x
  3689.                 sta        |c_strt_buffer
  3690.                 lda        <buff_ptr+2
  3691.                 sta        >buff_ptr+2,x
  3692.                 sta        |c_strt_buffer+2
  3693.  
  3694.                 lda        <rqst_cnt
  3695.                 sta        >rqst_cnt,x
  3696.                 sta        |c_strt_rqst_cnt
  3697.                 lda        <rqst_cnt+2
  3698.                 sta        >rqst_cnt+2,x
  3699.                 sta        |c_strt_rqst_cnt+2
  3700.  
  3701.                 lda        <block_num
  3702.                 sta        >block_num,x
  3703.                 sta        |c_strt_blk_num
  3704.                 lda        <block_num+2
  3705.                 sta        >block_num+2,x
  3706.                 sta        |c_strt_blk_num+2
  3707.                                         ;
  3708.                                         ; Validate Flag for the Read Cache
  3709.                                         ; Routines
  3710.                                         ;
  3711.                 dec        |cache_valid
  3712.  
  3713.                 txa
  3714.                 tcd
  3715.  
  3716.                 plp
  3717.                 pla
  3718.                 rts
  3719.                                         ;
  3720.                                         ; Internal Data
  3721.                                         ;
  3722. @blk_cnt        dc.l    null
  3723.                                         ;
  3724.                                         ; The following values are used to advance
  3725.                                         ; the starting point of the cache calls.
  3726.                                         ;
  3727.                 EXPORT        c_strt_buffer
  3728.                 EXPORT        c_strt_rqst_cnt
  3729.                 EXPORT        c_strt_blk_num
  3730.                 EXPORT        cache_valid
  3731.  
  3732. c_strt_buffer    dc.l    null            ;Starting Buffer Pointer
  3733. c_strt_rqst_cnt    dc.l    null            ;Starting Request Count
  3734. c_strt_blk_num    dc.l    null            ;Starting Block Number
  3735. cache_valid        dc.w    null
  3736.  
  3737.                 ENDP
  3738.  
  3739.                 EJECT
  3740.  
  3741. ;*******************************************************
  3742. ;
  3743. ;    'w_update_cache'
  3744. ;
  3745. ;    This routine is used when writting data to the disk
  3746. ;    with a cache priority of $0000.  If the block is in
  3747. ;    the cache, then the cache will be updated.  If not,
  3748. ;    then nothing will happen.
  3749. ;
  3750. ;    Inputs:        Acc            =    Unspecified
  3751. ;                Y register    =    Unspecified
  3752. ;                X register    =    Unspecified
  3753. ;                P register    =    0=M=X=e
  3754. ;                Direct Page    =    Ours
  3755. ;                Data Bank    =    Ours
  3756. ;                Carry Clear    =    Always place in cache
  3757. ;                Carry set    =    Only place in cache if
  3758. ;                                already there.
  3759. ;
  3760. ;    Outputs:    Acc            =    Unspecified
  3761. ;                Y register    =    Unspecified
  3762. ;                X register    =    Unspecified
  3763. ;                P register    =    0=M=X=e
  3764. ;                Direct Page    =    Ours
  3765. ;                Data Bank    =    Ours
  3766. ;
  3767. ;    Errors:        Carry set if requested block is not
  3768. ;                added to the cache.
  3769. ;
  3770. ;*******************************************************
  3771.  
  3772.                 EXPORT    w_update_cache
  3773. w_update_cache    PROC
  3774.                                         ;
  3775.                                         ; Zero Deferred Write failed flag.
  3776.                                         ;
  3777.                 stz        @deferred
  3778.                                         ;
  3779.                                         ; Preserve Carry Flag for later.
  3780.                                         ;
  3781.                 php
  3782.                                         ;
  3783.                                         ; Set GS/OS Direct Page
  3784.                                         ;
  3785.                 lda        |gsos_dpage
  3786.                 tcd
  3787.                                         ;
  3788.                                         ; Preserve Block Number and request
  3789.                                         ; count.  Set count to 1 block per
  3790.                                         ; call.
  3791.                                         ;
  3792.                 lda        <buff_ptr
  3793.                 sta        @orig_buff
  3794.  
  3795.                 lda        <rqst_cnt
  3796.                 sta        @bytes_rem
  3797.  
  3798.                 lda        <block_num
  3799.                 sta        @start_blk
  3800.  
  3801.                 lda        <buff_ptr+2
  3802.                 sta        @orig_buff+2
  3803.  
  3804.                 lda        <rqst_cnt+2
  3805.                 sta        @bytes_rem+2
  3806.  
  3807.                 lda        <block_num+2
  3808.                 sta        @start_blk+2
  3809.                                         ;
  3810.                                         ; Is the requested block in the cache?
  3811.                                         ;
  3812. @do_cache        plp
  3813.                 php
  3814.                 jsr        put_in_cache
  3815.                 bcc        @cached            ;Carry set only if a deferred write
  3816.                 dec        @deferred        ;failed to go in the cache.
  3817.                                         ;
  3818.                                         ; Advance to the next block.
  3819.                                         ;
  3820. @cached            inc        <block_num
  3821.                 bne        @over
  3822.                 inc        <block_num+2
  3823.                                         ;
  3824.                                         ; Bump Buffer Pointer.
  3825.                                         ;
  3826. @over            clc
  3827.                 lda        <buff_ptr
  3828.                 adc        <blk_size
  3829.                 sta        <buff_ptr
  3830.                 bcc        @over_1
  3831.                 inc        <buff_ptr+2
  3832.                                         ;
  3833.                                         ; Any Data Left
  3834.                                         ;
  3835. @over_1            sec
  3836.                 lda        @bytes_rem
  3837.                 sbc        <blk_size
  3838.                 sta        @bytes_rem
  3839.                 sta        |temp_acc
  3840.  
  3841.                 lda        @bytes_rem+2
  3842.                 sbc        #null
  3843.                 sta        @bytes_rem+2
  3844.                 ora        |temp_acc
  3845.  
  3846.                 bne        @do_cache        ;Yes.
  3847.                 clc
  3848.                                         ;
  3849.                                         ; Restore Values.
  3850.                                         ;
  3851.  
  3852. @restore        lda        @orig_buff
  3853.                 sta        <buff_ptr
  3854.  
  3855.                 lda        @start_blk
  3856.                 sta        <block_num
  3857.  
  3858.                 lda        @orig_buff+2
  3859.                 sta        <buff_ptr+2
  3860.  
  3861.                 lda        @start_blk+2
  3862.                 sta        <block_num+2
  3863.                                         ;
  3864.                                         ; Exit.
  3865.                                         ;
  3866.                 lda        |direct_page
  3867.                 tcd
  3868.  
  3869.                 lda        @deferred
  3870.                 beq        @clean_out
  3871.                 plp                        ;Restore the Stack.
  3872.                 sec
  3873.                 rts
  3874.  
  3875. @clean_out        plp                        ;Restore the Stack.
  3876.                 clc
  3877.                 rts
  3878.                                         ;
  3879.                                         ; Internal Data
  3880.                                         ;
  3881. @deferred        dc.w    null
  3882. @orig_buff        dc.l    null
  3883. @bytes_rem        dc.l    null
  3884. @start_blk        dc.l    null
  3885.  
  3886.                 ENDP
  3887.  
  3888.                 EJECT
  3889.  
  3890. ;*******************************************************
  3891. ;
  3892. ;    'put_in_cache'
  3893. ;
  3894. ;    This routine is used to place the current block in
  3895. ;    the cache.  First we will check if the requested
  3896. ;    block is in the cache.  If the block is not in the
  3897. ;    cache then we will add it.  if there is no room and
  3898. ;    the driver call was issued in deferred mode then we
  3899. ;    will exit with the carry set.  In all other cases
  3900. ;    we will exit Carry Clear.
  3901. ;
  3902. ;    Inputs:        Acc            =    Unspecified
  3903. ;                Y register    =    Unspecified
  3904. ;                X register    =    Unspecified
  3905. ;                P register    =    0=M=X=e
  3906. ;                Direct Page    =    Ours
  3907. ;                Data Bank    =    Ours
  3908. ;                Carry Clear    =    Always place in cache
  3909. ;                Carry set    =    Only place in cache if
  3910. ;                                already there.
  3911. ;
  3912. ;    Outputs:    Acc            =    Unspecified
  3913. ;                Y register    =    Unspecified
  3914. ;                X register    =    Unspecified
  3915. ;                P register    =    0=M=X=e
  3916. ;                Direct Page    =    Ours
  3917. ;                Data Bank    =    Ours
  3918. ;
  3919. ;    Errors:        Carry set if requested block is not
  3920. ;                added to the cache in deferred mode
  3921. ;                only.
  3922. ;
  3923. ;*******************************************************
  3924.  
  3925.                 EXPORT    put_in_cache
  3926. put_in_cache    PROC
  3927.                                         ;
  3928.                                         ; Is the requested block in the cache?
  3929.                                         ;
  3930.                 php
  3931.  
  3932.                 clc
  3933.                 jsl        cache_find_blk
  3934.  
  3935.                 bcc        @move_it_in        ;Yes. It is.
  3936.                 plp
  3937.                 bcs        @clc
  3938.                                         ;
  3939.                                         ; Not there.  Allocate space.
  3940.                                         ;
  3941.                 jsl        cache_add_blk
  3942.                 bcc        @skip_fix
  3943.                 lda        <cache_prio        ;Deferred Mode?
  3944.                 bpl        @clc            ;No.  Exit Carry Clear.
  3945.                 rts                        ;Yes. Exit carry set
  3946.                                         ;
  3947.                                         ; Move the block in.
  3948.                                         ;
  3949. @move_it_in        plp                        ;Restore the stack.
  3950.  
  3951. @skip_fix        pei        <buff_ptr+2
  3952.                 pei        <buff_ptr
  3953.                 pei        <cache_ptr+2
  3954.                 pei        <cache_ptr
  3955.                 pea        $0000
  3956.                 pei        <blk_size
  3957.                 pea        |move_sinc_dinc
  3958.                 jsl        move_info
  3959.                                         ;
  3960.                                         ; Exit.
  3961.                                         ;
  3962. @clc            clc
  3963. @rts            rts
  3964.  
  3965.                 ENDP
  3966.  
  3967.                 EJECT
  3968.  
  3969. ;*******************************************************
  3970. ;
  3971. ;    'r_get_cache'
  3972. ;
  3973. ;    This routine is used when reading data from the disk
  3974. ;    with a cache priority of $0000.  If the block is in
  3975. ;    the cache, then the data will be updated.  If not,
  3976. ;    then nothing will happen.
  3977. ;
  3978. ;    Inputs:        Acc            =    Unspecified
  3979. ;                Y register    =    Unspecified
  3980. ;                X register    =    Unspecified
  3981. ;                P register    =    0=M=X=e
  3982. ;                Direct Page    =    Ours
  3983. ;                Data Bank    =    Ours
  3984. ;                Carry Clear    =    Always place in cache
  3985. ;                Carry set    =    Only place in cache if
  3986. ;                                already there.
  3987. ;
  3988. ;    Outputs:    Acc            =    Unspecified
  3989. ;                Y register    =    Unspecified
  3990. ;                X register    =    Unspecified
  3991. ;                P register    =    0=M=X=e
  3992. ;                Direct Page    =    Ours
  3993. ;                Data Bank    =    Ours
  3994. ;
  3995. ;    Errors:        Carry set if requested block is not
  3996. ;                added to the cache.
  3997. ;
  3998. ;*******************************************************
  3999.  
  4000.                 EXPORT    r_get_cache
  4001. r_get_cache        PROC
  4002.                                         ;
  4003.                                         ; Preserve Carry Flag for later.
  4004.                                         ;
  4005.                 php
  4006.                                         ;
  4007.                                         ; Check Validity of the call.
  4008.                                         ;
  4009.                 lda        |cache_valid
  4010.                 bmi        @valid
  4011.  
  4012.                 plp
  4013.                 lda        #drvr_bad_code
  4014.                 sec
  4015.                 rts
  4016.                                         ;
  4017.                                         ; Set GS/OS Direct Page
  4018.                                         ;
  4019. @valid            lda        |gsos_dpage
  4020.                 tcd
  4021.                                         ;
  4022.                                         ; Get Request count.
  4023.                                         ;
  4024.                 lda        |c_strt_rqst_cnt
  4025.                 sta        @bytes_rem
  4026.                 lda        |c_strt_rqst_cnt+2
  4027.                 sta        @bytes_rem+2
  4028.                                         ;
  4029.                                         ; Is the requested block in the cache?
  4030.                                         ;
  4031. @do_cache        plp
  4032.                 php
  4033.                 jsr        get_from_cache
  4034.                                         ;
  4035.                                         ; Advance to the next block.
  4036.                                         ;
  4037.                 inc        <block_num
  4038.                 bne        @over
  4039.                 inc        <block_num+2
  4040.                                         ;
  4041.                                         ; Bump Buffer Pointer.
  4042.                                         ;
  4043. @over            clc
  4044.                 lda        <buff_ptr
  4045.                 adc        <blk_size
  4046.                 sta        <buff_ptr
  4047.                 bcc        @over_1
  4048.                 inc        <buff_ptr+2
  4049.                                         ;
  4050.                                         ; Any Data Left
  4051.                                         ;
  4052. @over_1            sec
  4053.                 lda        @bytes_rem
  4054.                 sbc        <blk_size
  4055.                 sta        @bytes_rem
  4056.                 sta        |temp_acc
  4057.  
  4058.                 lda        @bytes_rem+2
  4059.                 sbc        #null
  4060.                 sta        @bytes_rem+2
  4061.                 ora        |temp_acc
  4062.  
  4063.                 bne        @do_cache        ;Yes.
  4064.                                         ;
  4065.                                         ; Exit.
  4066.                                         ;
  4067.                 stz        |cache_valid    ;Cache Values no longer valid
  4068.  
  4069.                 lda        |direct_page
  4070.                 tcd
  4071.  
  4072.                 plp                        ;Restore the Stack.
  4073.                 clc
  4074.                 rts
  4075.                                     ;
  4076.                                     ; Internal Data
  4077.                                     ;
  4078. @bytes_rem        dc.l    null
  4079.  
  4080.                 ENDP
  4081.  
  4082.                 EJECT
  4083.  
  4084. ;*******************************************************
  4085. ;
  4086. ;    'get_from_cache'
  4087. ;
  4088. ;    This routine is used to get the current block from
  4089. ;    the cache.  First we will check if the requested
  4090. ;    block is in the cache.  If the block is not in the
  4091. ;    cache then we will exit with the Carry Set.  If it
  4092. ;    is found, then we will move it to the requested ram
  4093. ;    and exit Carry Clear.
  4094. ;
  4095. ;    Inputs:        Acc            =    Unspecified
  4096. ;                Y register    =    Unspecified
  4097. ;                X register    =    Unspecified
  4098. ;                P register    =    0=M=X=e
  4099. ;                Direct Page    =    Ours
  4100. ;                Data Bank    =    Ours
  4101. ;
  4102. ;    Outputs:    Acc            =    Unspecified
  4103. ;                Y register    =    Unspecified
  4104. ;                X register    =    Unspecified
  4105. ;                P register    =    0=M=X=e
  4106. ;                Direct Page    =    Ours
  4107. ;                Data Bank    =    Ours
  4108. ;
  4109. ;    Errors:        Carry set if requested block is not
  4110. ;                in the cache.
  4111. ;
  4112. ;*******************************************************
  4113.  
  4114.                 EXPORT    get_from_cache
  4115. get_from_cache    PROC
  4116.                                         ;
  4117.                                         ; Is the requested block in the cache?
  4118.                                         ;
  4119.                 php
  4120.  
  4121.                 clc
  4122.                 jsl        cache_find_blk
  4123.  
  4124.                 bcc        @move_it_in        ;Yes. It is.
  4125.                 plp
  4126.                 bcs        @rts
  4127.                                         ;
  4128.                                         ; Not there.  Allocate space.
  4129.                                         ;
  4130.                 jsl        cache_add_blk
  4131.                 bcs        @rts
  4132.  
  4133.                 pei        <buff_ptr+2
  4134.                 pei        <buff_ptr
  4135.                 pei        <cache_ptr+2
  4136.                 pei        <cache_ptr
  4137.                 pea        $0000
  4138.                 pei        <blk_size
  4139.                 pea        |move_sinc_dinc
  4140.                 jsl        move_info
  4141.  
  4142.                 bra        @clc
  4143.                                         ;
  4144.                                         ; Move the block in.
  4145.                                         ;
  4146. @move_it_in        plp                        ;Restore the stack.
  4147.  
  4148. @skip_fix        pei        <cache_ptr+2
  4149.                 pei        <cache_ptr
  4150.                 pei        <buff_ptr+2
  4151.                 pei        <buff_ptr
  4152.                 pea        $0000
  4153.                 pei        <blk_size
  4154.                 pea        |move_sinc_dinc
  4155.                 jsl        move_info
  4156.                                         ;
  4157.                                         ; Exit.
  4158.                                         ;
  4159. @clc            clc
  4160. @rts            rts
  4161.  
  4162.                 ENDP
  4163.  
  4164.                 EJECT
  4165.  
  4166. ;*******************************************************
  4167. ;
  4168. ;    'ko_cache'
  4169. ;
  4170. ;    This routine is used to kill all blocks that are
  4171. ;    cached that are included in a device specific write
  4172. ;    type call.
  4173. ;
  4174. ;    Inputs:        Acc            =    Unspecified
  4175. ;                Y register    =    Unspecified
  4176. ;                X register    =    Unspecified
  4177. ;                P register    =    0=M=X=e
  4178. ;                Direct Page    =    Ours
  4179. ;                Data Bank    =    Ours
  4180. ;
  4181. ;    Outputs:    Acc            =    Unspecified
  4182. ;                Y register    =    Unspecified
  4183. ;                X register    =    Unspecified
  4184. ;                P register    =    0=M=X=e
  4185. ;                Direct Page    =    Ours
  4186. ;                Data Bank    =    Ours
  4187. ;
  4188. ;    Errors:        None.
  4189. ;
  4190. ;*******************************************************
  4191.  
  4192.                 EXPORT    ko_cache
  4193. ko_cache        PROC
  4194.                                     ;
  4195.                                     ; Switch Direct Pages.
  4196.                                     ;
  4197.                 lda        |gsos_dpage
  4198.                 tcd
  4199.                                     ;
  4200.                                     ; Preserve the block number on direct
  4201.                                     ; page.
  4202.                                     ;
  4203.                 lda        <block_num
  4204.                 sta        |scratch0
  4205.                 lda        <block_num+2
  4206.                 sta        |scratch1
  4207.                                     ;
  4208.                                     ; Set our starting block number on
  4209.                                     ; direct page.
  4210.                                     ;
  4211.                 lda        |killer_blk
  4212.                 sta        <block_num
  4213.                 lda        |killer_blk+2
  4214.                 sta        <block_num+2
  4215.                                     ;
  4216.                                     ; Get the requested count and devide
  4217.                                     ; by block size to get the loop counter.
  4218.                                     ; If Count = 0, then exit.
  4219.                                     ;
  4220.                 lda        <rqst_cnt+2
  4221.                 sta        |divend+2
  4222.                 lda        <rqst_cnt
  4223.                 sta        |divend
  4224.                 ora        <rqst_cnt+2
  4225.                 bne        @do_devide
  4226.  
  4227.                 clc
  4228. @rts            bra        @restore
  4229.                                     ;
  4230.                                     ; Call divide routine.
  4231.                                     ;
  4232. @do_devide        lda        <blk_size
  4233.                 sta        |divsor
  4234.  
  4235.                 jsr        divide
  4236.                 bcc        @over_divide
  4237.                 lda        #drvr_bad_cnt    ;non-integral rqst count.
  4238.                 sec
  4239.                 bra        @restore
  4240.                                     ;
  4241.                                     ; Count = count -1.  This way we can
  4242.                                     ; use a BMI to exit with.
  4243.                                     ;
  4244. @over_divide    lda        |result+2
  4245.                 sta        @blk_cnt+2
  4246.                 lda        |result
  4247.                 sta        @blk_cnt
  4248.                 bne        @over_dec_high
  4249.                 dec        @blk_cnt+2
  4250. @over_dec_high    dec        @blk_cnt
  4251.                                     ;
  4252.                                     ; Setup is now completed.  Now we start to
  4253.                                     ; check to see if the blocks are in the
  4254.                                     ; cache.
  4255.                                     ;
  4256. @chk_blk_loop    jsl        cache_kil_blk
  4257.                                     ;
  4258.                                     ; Are there any more to do?
  4259.                                     ;
  4260.                 lda        @blk_cnt
  4261.                 bne        @over_dec
  4262.                 dec        @blk_cnt+2
  4263.                 bpl        @over_dec
  4264.                                     ;
  4265.                                     ; No. Count is exausted.
  4266.                                     ;
  4267.                 clc
  4268.                 bra        @restore
  4269.                                     ;
  4270.                                     ; Yes. Finish the DEC and update
  4271.                                     ; the block number.
  4272.                                     ;
  4273. @over_dec        dec        @blk_cnt
  4274.  
  4275.                 inc        <block_num
  4276.                 bne        @chk_blk_loop
  4277.                 inc        <block_num+2
  4278.                 bra        @chk_blk_loop
  4279.                                     ;
  4280.                                     ; We are finished.  We don't need to
  4281.                                     ; know if we were succesfull.  We only
  4282.                                     ; need to restore the state of the
  4283.                                     ; corrupted direct page values while
  4284.                                     ; preserving the Acc. and Carry bit.
  4285.                                     ;
  4286. @restore        pha
  4287.                 php
  4288.                 lda        |scratch0
  4289.                 sta        <block_num
  4290.                 lda        |scratch1
  4291.                 sta        <block_num+2
  4292.  
  4293.                 lda        |direct_page
  4294.                 tcd
  4295.  
  4296.                 plp
  4297.                 pla
  4298.                 rts
  4299.                                     ;
  4300.                                     ; Internal Data
  4301.                                     ;
  4302. @blk_cnt        dc.l    null
  4303.  
  4304.                 ENDP
  4305.  
  4306.                 EJECT
  4307.  
  4308.                 ELSE
  4309.  
  4310. ;-------------------------------------------------------------------------------
  4311.  
  4312.                 EXPORT        put_in_cache
  4313.  
  4314. put_in_cache    PROC
  4315.  
  4316.                 EXPORT        get_from_cache
  4317.                 EXPORT        c_strt_buffer
  4318.                 EXPORT        c_strt_rqst_cnt
  4319.                 EXPORT        c_strt_blk_num
  4320.                 EXPORT        cache_valid
  4321.  
  4322. get_from_cache    sec
  4323.                 rts
  4324.  
  4325. c_strt_buffer
  4326. c_strt_rqst_cnt
  4327. c_strt_blk_num
  4328. cache_valid        dc.w    null
  4329.  
  4330.                 ENDP
  4331.  
  4332.                 EJECT
  4333.  
  4334.                 ENDIF
  4335.  
  4336. ;-------------------------------------------------------------------------------
  4337.  
  4338. ;____Device_Tests____
  4339. ;*******************************************************
  4340. ;
  4341. ;    'unit_state'
  4342. ;
  4343. ;    Tests the Target Device to see if it is ready to
  4344. ;    accept our commands.  If the device responds with a
  4345. ;    CHECK CONDITION, then we will find out why and
  4346. ;    perform the correct actions.
  4347. ;
  4348. ;    Inputs:        Acc            =    Unspecified
  4349. ;                Y register    =    Unspecified
  4350. ;                X register    =    Unspecified
  4351. ;                P register    =    0=M=X=e
  4352. ;                Direct Page    =    Ours
  4353. ;                Data Bank    =    Ours
  4354. ;                <dib_ptr    =    Called DIB
  4355. ;
  4356. ;    Outputs:    Acc            =    Error Code if any
  4357. ;                Y register    =    Unspecified
  4358. ;                X register    =    Unspecified
  4359. ;                P register    =    0=M=X=e
  4360. ;                Direct Page    =    Ours
  4361. ;                Data Bank    =    Ours
  4362. ;                <dib_ptr    =    Called DIB
  4363. ;
  4364. ;    Errors:        Carry set if Unit no ready.
  4365. ;
  4366. ;*******************************************************
  4367.  
  4368.                 EXPORT    unit_state
  4369. unit_state        PROC
  4370.                                         ;
  4371.                                         ; This device is removable.  Now we
  4372.                                         ; need to check to see if the unit
  4373.                                         ; has gone offline, (then we need to
  4374.                                         ; report that to the OS) or if the
  4375.                                         ; unit has come back online (Rebuild
  4376.                                         ; the DIBs).
  4377.                                         ;
  4378.                 jsr        test_unit_rdy    ;Is there anything that we should know about?
  4379.                 bcc        @ready_to_go    ;No.
  4380.  
  4381.                 lda        |auto_sense_data+\
  4382.                         rqst_sens.sense_key
  4383.                 beq        @ready_to_go
  4384.  
  4385.                 and        #$00ff
  4386.                 cmp        #$0006
  4387.                 beq        @do_switch
  4388.  
  4389. ;-------------------------------------------------------------------------------
  4390.  
  4391.                 IF            scsi_dtype = direct_acc        THEN
  4392.  
  4393.                 lda        auto_sense_data+\        ;Was it a RESET?
  4394.                         rqst_sens.addnl_sens_code
  4395.                 and        #$00fe
  4396.                 cmp        #$0028            ;Checking for $28 (Medium Changed), $29 (RESET)
  4397.                 bne        @io_error
  4398.  
  4399.                 ENDIF
  4400.  
  4401. ;-------------------------------------------------------------------------------
  4402.  
  4403.                 IF            scsi_dtype = apple_cd        THEN
  4404.  
  4405.                 lda        auto_sense_data+\        ;Was it a RESET?
  4406.                         rqst_sens.addnl_sens_code
  4407.                 and        #$00ff
  4408.                 cmp        #$00b7            ;Checking for $B7 (Media being mounted)
  4409.                 beq        @do_switch
  4410.                 cmp        #$00b0            ;Checking for $B0 (NO MEDIA)
  4411.                 beq        @off_line
  4412.                 and        #$00fe
  4413.                 cmp        #$0028            ;Checking for $28 (Medium Changed), $29 (RESET)
  4414.                 bne        @io_error
  4415.                                         ;
  4416.                                         ; Set this location to a $B0.  This will
  4417.                                         ; prevent problems if the device is reset
  4418.                                         ; durring startup while auto sensing is
  4419.                                         ; off.
  4420.                                         ;
  4421.                 lda        #$00b0
  4422.                 sta        auto_sense_data+\
  4423.                         rqst_sens.addnl_sens_code
  4424.                 bra        unit_state
  4425.  
  4426.                 ENDIF
  4427.  
  4428. ;-------------------------------------------------------------------------------
  4429.  
  4430.                                             ;
  4431.                                             ; Rebuild the DIBs.
  4432.                                             ;
  4433. @do_switch        jsr        test_unit_rdy        ;Is it ready yet?
  4434.                 bcc        @its_ready            ;Yes.
  4435.                 lda        auto_sense_data+\    ;Is there media in the drive?
  4436.                         rqst_sens.addnl_sens_code
  4437.                 and        #$00ff
  4438.                 cmp        #$00b0                ;Checking for $B0 (NO MEDIA)
  4439.                 bne        @do_switch            ;No.
  4440.  
  4441. @its_ready        jsr        set_512_mode
  4442.                                         ;
  4443.                                         ; Issue the READ CAPACITY Command.
  4444.                                         ;
  4445.                 jsr        read_capacity
  4446.                 bcs        @over_0            ;Was there an error?
  4447.                                         ;
  4448.                                         ; Get the Block Count (Stored
  4449.                                         ; High >> Low.  Must be switched
  4450.                                         ; to Low >> High).  This is the last
  4451.                                         ; readable block number.  Add 1 to
  4452.                                         ; it for comparison reasons.
  4453.                                         ;
  4454.                 lda        |block.count\
  4455.                         +internal_buff\
  4456.                         +2
  4457.                 xba
  4458.                 adc        #$0001
  4459.                 sta        |t_dvc_blocks
  4460.                 lda        |block.count\
  4461.                         +internal_buff
  4462.                 xba
  4463.                 adc        #null
  4464.                 sta        |t_dvc_blocks+2
  4465.  
  4466. @over_0            stz        |trash_it        ;DO NOT TRASH THIS DISK.
  4467.  
  4468.                 pei        <dib_ptr
  4469.                 pei        <dib_ptr+2
  4470.  
  4471.                 jsr        rebld_dibs        ;Rebuild DIBs and Issue a DISK_SW for each
  4472.  
  4473.                 tax
  4474.                 pla
  4475.                 sta        <dib_ptr+2
  4476.                 pla
  4477.                 sta        <dib_ptr
  4478.                 txa
  4479.  
  4480.                 php
  4481.                                         ;
  4482.                                         ; Restore the original Direct Page values.
  4483.                                         ;
  4484.                 jsr        set_our_dp
  4485.                 plp
  4486.                 bcc        @switch_error
  4487.                 jsr        test_unit_rdy
  4488.                 bcs        @io_error
  4489.                                         ;
  4490.                                         ; Disk Switched Error.
  4491.                                         ;
  4492. @switch_error    lda        #drvr_dsk_swch
  4493.                 sec
  4494.                 rts
  4495.                                         ;
  4496.                                         ; Are we really ready to go?  If the
  4497.                                         ; dvc_hard_sw flag is set, then we
  4498.                                         ; will clear it and report the device
  4499.                                         ; as switched.
  4500.                                         ;
  4501. @ready_to_go    ldy        #dib.dvcflag
  4502.                 lda        [dib_ptr],y
  4503.                 tax
  4504.  
  4505.                 and        #dvc_hard_sw
  4506.                 beq        @no_switch
  4507.  
  4508.                 txa
  4509.                 and        #dvc_hard_sw--\
  4510.                         $ffff
  4511.                 sta        [dib_ptr],y
  4512.  
  4513. @no_switch        lda        #null
  4514.                 clc
  4515. @rts            rts
  4516.                                         ;
  4517.                                         ; Some kind of I/O Error.
  4518.                                         ;
  4519. @io_error        lda        #drvr_io
  4520.                 sec
  4521.                 rts
  4522.                                         ;
  4523.                                         ; Device is currently offline.
  4524.                                         ;
  4525. @off_line        lda        #drvr_off_line
  4526.                 sec
  4527.                 rts
  4528.  
  4529.                 ENDP
  4530.  
  4531.                 EJECT
  4532.  
  4533. ;*******************************************************
  4534. ;
  4535. ;    'test_unit_rdy'
  4536. ;
  4537. ;    Test the Target Device to see if it is ready to
  4538. ;    accept our commands.  If the device responds with a
  4539. ;    CHECK CONDITION, then it will be up to the caller of
  4540. ;    this routine to find out why.  This is not a test
  4541. ;    routine.
  4542. ;
  4543. ;    Inputs:        Acc            =    Unspecified
  4544. ;                Y register    =    Unspecified
  4545. ;                X register    =    Unspecified
  4546. ;                P register    =    0=M=X=e
  4547. ;                Direct Page    =    Ours
  4548. ;                Data Bank    =    Ours
  4549. ;
  4550. ;    Outputs:    Acc            =    Error Code if any
  4551. ;                Y register    =    Unspecified
  4552. ;                X register    =    Unspecified
  4553. ;                P register    =    0=M=X=e
  4554. ;                Direct Page    =    Ours
  4555. ;                Data Bank    =    Ours
  4556. ;
  4557. ;    Errors:        Carry set if Unit no ready.
  4558. ;
  4559. ;*******************************************************
  4560.  
  4561.                 EXPORT    test_unit_rdy
  4562. test_unit_rdy    PROC
  4563.                                     ;
  4564.                                     ; Set Internal Command Flag
  4565.                                     ;
  4566.                 dec        |internal
  4567.                                     ;
  4568.                                     ; Set Parm Pointer.
  4569.                                     ;
  4570.                 lda        #@test_unit_p
  4571.                 sta        <scsi_mdrvr
  4572.                 lda        #^@test_unit_p
  4573.                 sta        <scsi_mdrvr+2
  4574.                                     ;
  4575.                                     ; It's a Status Call.
  4576.                                     ;
  4577.                 lda        #scsit_stat
  4578.                 sta        |call_type
  4579.                                     ;
  4580.                                     ; Issue the Call
  4581.                                     ;
  4582.                 jmp        |main_drvr
  4583.                                     ;
  4584.                                     ; Data for this call
  4585.                                     ; TEST UNIT READY Command Packet
  4586.                                     ;
  4587. @test_unit_p    dc.b    $00            ;Command Number
  4588.                 dc.b    $00            ;SCSI Command Flags
  4589.                 dcb.b    3,$00        ;Reserved
  4590.                 dc.b    $00            ;Vendor Unique
  4591.                 dcb.b    6,$00        ;Resrved
  4592.  
  4593.                 ENDP
  4594.  
  4595.                 EJECT
  4596.  
  4597. ;*******************************************************
  4598. ;
  4599. ;    'CHK_PLAY_MODE'
  4600. ;
  4601. ;    This command is used to tell if the device is
  4602. ;    currently in Audio Play Mode.
  4603. ;
  4604. ;    Inputs:        Acc            =    Unspecified
  4605. ;                Y register    =    Unspecified
  4606. ;                X register    =    Unspecified
  4607. ;                P register    =    0=M=X=e
  4608. ;                Direct Page    =    Ours
  4609. ;                Data Bank    =    Ours
  4610. ;
  4611. ;    Outputs:    Acc            =    Error Code if any
  4612. ;                Y register    =    Unspecified
  4613. ;                X register    =    Unspecified
  4614. ;                P register    =    0=M=X=e
  4615. ;                Direct Page    =    Ours
  4616. ;                Data Bank    =    Ours
  4617. ;
  4618. ;    Errors:        Carry set not in play mode
  4619. ;
  4620. ;*******************************************************
  4621.  
  4622. ;-------------------------------------------------------------------------------
  4623.  
  4624.                 IF        scsi_dtype = apple_cd    THEN
  4625.  
  4626.                 EXPORT    chk_play_mode
  4627. chk_play_mode    PROC
  4628.                                         ;
  4629.                                         ; First, disable auto sensing.
  4630.                                         ;
  4631.                 ldy        #dib.rslt_ptr
  4632.                 lda        [dib_ptr],y
  4633.                 pha
  4634.                 lda        #null
  4635.                 sta        [dib_ptr],y
  4636.  
  4637.                 ldy        #dib.rslt_ptr+2
  4638.                 lda        [dib_ptr],y
  4639.                 pha
  4640.                 lda        #null
  4641.                 sta        [dib_ptr],y
  4642.                                         ;
  4643.                                         ; Set Internal Command Flag
  4644.                                         ;
  4645.                 dec        |internal
  4646.                                         ;
  4647.                                         ; Set Parm length.
  4648.                                         ;
  4649.                 lda        #$0006
  4650.                 sta        <rqst_cnt
  4651.                 stz        <rqst_cnt+2
  4652.                                         ;
  4653.                                         ; Set Parm Pointer.
  4654.                                         ;
  4655.                 lda        #@chk_play
  4656.                 sta        <scsi_mdrvr
  4657.                 lda        #^@chk_play
  4658.                 sta        <scsi_mdrvr+2
  4659.                                         ;
  4660.                                         ; Set Buff Pointer.
  4661.                                         ;
  4662.                 lda        #@play_data
  4663.                 sta        <buff_ptr
  4664.                 lda        #^@play_data
  4665.                 sta        <buff_ptr+2
  4666.                                         ;
  4667.                                         ; It's a Status Call.
  4668.                                         ;
  4669.                 lda        #scsit_stat
  4670.                 sta        |call_type
  4671.                                         ;
  4672.                                         ; Issue the Call
  4673.                                         ;
  4674.                 jsr        |main_drvr
  4675.                 bcs        @restore_dp        ;Carry is set.  Not play mode
  4676.                                         ;
  4677.                                         ; Check the Status.
  4678.                                         ;
  4679.                                         ; Status $00 = In play mode
  4680.                                         ;         $01 = Pause (Play Mode)
  4681.                                         ;         $02 = Muting (Play Mode)
  4682.                                         ;
  4683.                                         ;         $03 = Play completed (No Play)
  4684.                                         ;         $04 = Error (No Play)
  4685.                                         ;         $05 = Play not requested.
  4686.                                         ;
  4687.                 lda        @play_data
  4688.                 and        #$0007
  4689.                 cmp        #$0003            ; <3 = Carry Clear. =>3 = Carry set
  4690.                                         ;
  4691.                                         ; Restore the Direct Page Values.
  4692.                                         ;
  4693. @restore_dp        php
  4694.                 jsr        set_our_dp
  4695.                 plp
  4696.                                         ;
  4697.                                         ; Restore Auto Sensing Pointer.
  4698.                                         ;
  4699.                 ldy        #dib.rslt_ptr+2
  4700.                 pla
  4701.                 sta        [dib_ptr],y
  4702.  
  4703.                 ldy        #dib.rslt_ptr
  4704.                 pla
  4705.                 sta        [dib_ptr],y
  4706.  
  4707.                 rts
  4708.                                         ;
  4709.                                         ; AUDIO STATUS Command Packet
  4710.                                         ;
  4711. @chk_play        dc.b    $cc                ;Command Number
  4712.                 dc.b    null            ;SCSI Command Flags
  4713.                 dcb.b    10,null            ;Reserved
  4714.                                         ;
  4715.                                         ; Data received for this call
  4716.                                         ;
  4717. @play_data        dcb.b    6,null
  4718.  
  4719.                 ENDP
  4720.  
  4721.                 ENDIF
  4722.  
  4723. ;-------------------------------------------------------------------------------
  4724.  
  4725.                 EJECT
  4726.  
  4727. ;*******************************************************
  4728. ;
  4729. ;    The REQUEST SENSE Call is used to request any
  4730. ;    information from the target device that might tell
  4731. ;    us something about the way that the last call
  4732. ;    competed.  This call should always be issued if any
  4733. ;    SCSI Command returns from the SCSI Manager with a
  4734. ;    CHECK CONDITION in the status result field.  The
  4735. ;    data returned will be kept until the next REQUEST
  4736. ;    SENSE Command is issued.  A flag however will be set
  4737. ;    if any other commands are received by the SCSI Driver
  4738. ;    indicating that this data is outdated.
  4739. ;
  4740. ;    Inputs:        Acc            =    Unspecified
  4741. ;                Y register    =    Unspecified
  4742. ;                X register    =    Unspecified
  4743. ;                P register    =    0=M=X=e
  4744. ;                Direct Page    =    Ours
  4745. ;                Data Bank    =    Ours
  4746. ;
  4747. ;    Outputs:    Acc            =    Error Code if any
  4748. ;                |sense_data    =    Data returned by the device
  4749. ;                Y register    =    Unspecified
  4750. ;                X register    =    Unspecified
  4751. ;                P register    =    0=M=X=e
  4752. ;                Direct Page    =    Ours
  4753. ;                Data Bank    =    Ours
  4754. ;
  4755. ;    Errors:        Carry set if Unit no ready.
  4756. ;
  4757. ;*******************************************************
  4758.  
  4759.                 EXPORT    rqst_sense
  4760. rqst_sense        PROC
  4761.                                     ;
  4762.                                     ; Set Internal Command Flag
  4763.                                     ;
  4764.                 dec        |internal
  4765.                                     ;
  4766.                                     ; Set Parm Pointer.
  4767.                                     ;
  4768.                 lda        #@rqst_sens_p
  4769.                 sta        <scsi_mdrvr
  4770.                 lda        #^@rqst_sens_p
  4771.                 sta        <scsi_mdrvr+2
  4772.                                     ;
  4773.                                     ; Preserve the Current Direct
  4774.                                     ; Page values stored in the
  4775.                                     ; buff_ptr and rqst_cnt fields.
  4776.                                     ;
  4777.                 pei        <buff_ptr
  4778.                 pei        <buff_ptr+2
  4779.                 pei        <rqst_cnt
  4780.                 pei        <rqst_cnt+2
  4781.                                     ;
  4782.                                     ; Set our own buffer pointer
  4783.                                     ; for this call.
  4784.                                     ;
  4785.                 lda        #sense_data
  4786.                 sta        <buff_ptr
  4787.                 lda        #^sense_data
  4788.                 sta        <buff_ptr+2
  4789.                                     ;
  4790.                                     ; Set our own request count
  4791.                                     ; for this call.
  4792.                                     ;
  4793.                 lda        #$0010
  4794.                 sta        <rqst_cnt
  4795.                 stz        <rqst_cnt+2
  4796.                                     ;
  4797.                                     ; It's a Status Call.
  4798.                                     ;
  4799.                 lda        #scsit_stat
  4800.                 sta        |call_type
  4801.                                     ;
  4802.                                     ; Issue the Call
  4803.                                     ;
  4804.                 stz        @error
  4805.                 jsr        |main_drvr
  4806.                 bcc        @return_dp
  4807.                                     ;
  4808.                                     ; Save error code
  4809.                                     ;
  4810.                 sta        @error
  4811.                                     ;
  4812.                                     ; Restore the Direct Page Values.
  4813.                                     ;
  4814. @return_dp        pla
  4815.                 sta        <rqst_cnt+2
  4816.                 pla
  4817.                 sta        <rqst_cnt
  4818.                 pla
  4819.                 sta        <buff_ptr+2
  4820.                 pla
  4821.                 sta        <buff_ptr
  4822.                                     ;
  4823.                                     ; Restore the Acc resutl.
  4824.                                     ;
  4825.                 lda        @error
  4826.                 cmp        #$0001
  4827.                 rts
  4828.                                     ;
  4829.                                     ; Data for this call
  4830.                                     ;
  4831. @error            dc.w    null
  4832.                                     ;
  4833.                                     ; REQUEST SENSE Command Packet
  4834.                                     ;
  4835. @rqst_sens_p    dc.b    $03            ;Command Number
  4836.                 dc.b    $00            ;SCSI Command Flags
  4837.                 dcb.b    3,$00        ;Reserved
  4838.                 dc.b    $00            ;Vendor Unique
  4839.                 dcb.b    6,$00        ;Reserved
  4840.  
  4841.                 ENDP
  4842.  
  4843.                 EJECT
  4844.  
  4845. ;*******************************************************
  4846. ;
  4847. ;    'reserve_unit'
  4848. ;
  4849. ;    The RESERVE UNIT Call is used to reserve the target
  4850. ;    device for use by this host only.
  4851. ;
  4852. ;    Inputs:        Acc            =    Unspecified
  4853. ;                Y register    =    Unspecified
  4854. ;                X register    =    Unspecified
  4855. ;                P register    =    0=M=X=e
  4856. ;                Direct Page    =    Ours
  4857. ;                Data Bank    =    Ours
  4858. ;
  4859. ;    Outputs:    Acc            =    Error Code if any
  4860. ;                |sense_data    =    Data returned by the device
  4861. ;                Y register    =    Unspecified
  4862. ;                X register    =    Unspecified
  4863. ;                P register    =    0=M=X=e
  4864. ;                Direct Page    =    Ours
  4865. ;                Data Bank    =    Ours
  4866. ;
  4867. ;    Errors:        Carry set if Unit already reserved.
  4868. ;
  4869. ;*******************************************************
  4870.  
  4871.                 EXPORT    reserve_unit
  4872. reserve_unit    PROC
  4873.  
  4874.  
  4875.                 lda        #null
  4876.                 clc
  4877.                 rts
  4878.  
  4879.                 ENDP
  4880.  
  4881.                 EJECT
  4882.  
  4883. ;*******************************************************
  4884. ;
  4885. ;    'release_unit'
  4886. ;
  4887. ;    The RELEASE UNIT Call is used to release the target
  4888. ;    device from use by this host only.
  4889. ;
  4890. ;    Inputs:        Acc            =    Unspecified
  4891. ;                Y register    =    Unspecified
  4892. ;                X register    =    Unspecified
  4893. ;                P register    =    0=M=X=e
  4894. ;                Direct Page    =    Ours
  4895. ;                Data Bank    =    Ours
  4896. ;
  4897. ;    Outputs:    Acc            =    Error Code if any
  4898. ;                |sense_data    =    Data returned by the device
  4899. ;                Y register    =    Unspecified
  4900. ;                X register    =    Unspecified
  4901. ;                P register    =    0=M=X=e
  4902. ;                Direct Page    =    Ours
  4903. ;                Data Bank    =    Ours
  4904. ;
  4905. ;    Errors:        None.
  4906. ;
  4907. ;*******************************************************
  4908.  
  4909.                 EXPORT    release_unit
  4910. release_unit    PROC
  4911.  
  4912.                 lda        #null
  4913.                 clc
  4914.                 rts
  4915.  
  4916.                 ENDP
  4917.  
  4918.                 EJECT
  4919.             
  4920. ;*******************************************************
  4921. ;
  4922. ;    'mode_sense'
  4923. ;
  4924. ;    This routine issues an MODE SENSE call to the device.
  4925. ;        
  4926. ;    Inputs:        <dib_ptr    =    DIB start            (LONG)
  4927. ;                Acc            =    Unspecified
  4928. ;                Carry        =    Unspecified
  4929. ;                Y register    =    Unspecified
  4930. ;                X register    =    Unspecified
  4931. ;                P register    =    0=M=X=e
  4932. ;                Direct Page    =    Ours
  4933. ;                Data Bank    =    Ours
  4934. ;
  4935. ;    Outputs:    Acc            =    Unspecified
  4936. ;                Carry        =    Unspecified
  4937. ;                Y register    =    Unspecified
  4938. ;                X register    =    Unspecified
  4939. ;                P register    =    0=M=X=e
  4940. ;                Direct Page    =    Ours
  4941. ;                Data Bank    =    Ours
  4942. ;
  4943. ;    Errors:        None.
  4944. ;
  4945. ;*******************************************************
  4946.  
  4947.                 EXPORT    mode_sense
  4948. mode_sense        PROC
  4949.                                         ;
  4950.                                         ; Initialize the Page code to 1
  4951.                                         ;
  4952.                 lda        #$0001
  4953.                 sta        @page_code
  4954.                                         ;
  4955.                                         ; Set internal command flag
  4956.                                         ;
  4957. @try_again        dec        |internal
  4958.                                         ;
  4959.                                         ; Tell the Main Driver where
  4960.                                         ; our command structure resides.
  4961.                                         ;
  4962.                 lda        #@start_mode
  4963.                 sta        <scsi_mdrvr
  4964.                 lda        #^@start_mode
  4965.                 sta        <scsi_mdrvr+2
  4966.                                         ;
  4967.                                         ; And our buffer
  4968.                                         ;
  4969.                 lda        #internal_buff
  4970.                 sta        <buff_ptr
  4971.                 lda        #^internal_buff
  4972.                 sta        <buff_ptr+2
  4973.                                         ;
  4974.                                         ; And our length of $ff Bytes
  4975.                                         ;
  4976.                 lda        #$0014
  4977.                 sta        <rqst_cnt
  4978.                 stz        <rqst_cnt+2
  4979.                                         ;
  4980.                                         ; Set the Call Type and Issue the
  4981.                                         ; MODE SENSE Command.
  4982.                                         ;
  4983.                 lda        #scsit_stat
  4984.                 sta        |call_type
  4985.                 jsr        |main_drvr
  4986.                 bcc        @rts
  4987.                 pha
  4988.                 lda        @page_code
  4989.                 beq        @pla
  4990.                 pla
  4991.                 stz        @page_code
  4992.                 bra        @try_again
  4993.                 
  4994. @pla            pla
  4995. @rts            rts
  4996.                                         ;
  4997.                                         ; Data for the MODE SENSE Command
  4998.                                         ;
  4999. @start_mode        dc.b    $1a
  5000.                 dc.b    $00
  5001. @page_code        dc.b    $01
  5002.                 dcb.b    9,$00
  5003.  
  5004.                 ENDP
  5005.  
  5006.                 EJECT
  5007.             
  5008. ;*******************************************************
  5009. ;
  5010. ;    'read_capacity'
  5011. ;
  5012. ;    This routine issues an READ CAPACITY call to the
  5013. ;    device and then uses the data returned to fill in
  5014. ;    some of the blank holes in the DIB.
  5015. ;        
  5016. ;    Inputs:        <dib_ptr    =    DIB start            (LONG)
  5017. ;                Acc            =    Unspecified
  5018. ;                Carry        =    Unspecified
  5019. ;                Y register    =    Unspecified
  5020. ;                X register    =    Unspecified
  5021. ;                P register    =    0=M=X=e
  5022. ;                Direct Page    =    Ours
  5023. ;                Data Bank    =    Ours
  5024. ;
  5025. ;    Outputs:    Acc            =    Unspecified
  5026. ;                Carry        =    Unspecified
  5027. ;                Y register    =    Unspecified
  5028. ;                X register    =    Unspecified
  5029. ;                P register    =    0=M=X=e
  5030. ;                Direct Page    =    Ours
  5031. ;                Data Bank    =    Ours
  5032. ;
  5033. ;    Errors:        None.
  5034. ;
  5035. ;*******************************************************
  5036.  
  5037.                 EXPORT    read_capacity
  5038. read_capacity    PROC
  5039.  
  5040. ;-------------------------------------------------------------------------------
  5041.  
  5042.                 IF            block_dvc = true\
  5043.                 AND            character_dvc = false        THEN
  5044.                                         ;
  5045.                                         ; Set internal command flag
  5046.                                         ;
  5047.                 dec        |internal
  5048.                                         ;
  5049.                                         ; Tell the Main Driver where
  5050.                                         ; our command structure resides.
  5051.                                         ;
  5052.                 lda        #@read_cap
  5053.                 sta        <scsi_mdrvr
  5054.                 lda        #^@read_cap
  5055.                 sta        <scsi_mdrvr+2
  5056.                                         ;
  5057.                                         ; And our buffer
  5058.                                         ;
  5059.                 lda        #internal_buff
  5060.                 sta        <buff_ptr
  5061.                 lda        #^internal_buff
  5062.                 sta        <buff_ptr+2
  5063.                                         ;
  5064.                                         ; And our length of $ff Bytes
  5065.                                         ;
  5066.                 lda        #$0008
  5067.                 sta        <rqst_cnt
  5068.                 stz        <rqst_cnt+2
  5069.                                         ; Set the Call Type and Issue the
  5070.                                         ; READ CAPACITY Command.
  5071.                                         ;
  5072.                 lda        #scsit_stat
  5073.                 sta        |call_type
  5074.                 jsr        |main_drvr
  5075.                 rts
  5076.                                         ;
  5077.                                         ; Data for the READ CAPACITY Command
  5078.                                         ;
  5079. @read_cap        dc.b    $25
  5080.                 dcb.b    11,$00
  5081.  
  5082.                 ELSE
  5083.  
  5084. ;-------------------------------------------------------------------------------
  5085.  
  5086.                 lda        #null
  5087.                 clc
  5088.                 rts
  5089.  
  5090.                 ENDIF
  5091.  
  5092. ;-------------------------------------------------------------------------------
  5093.  
  5094.                 ENDP
  5095.  
  5096.                 EJECT
  5097.  
  5098. ;*******************************************************
  5099. ;
  5100. ;    'get_data_status'
  5101. ;
  5102. ;    The GET DATA STATUS Call is used to find out how
  5103. ;    much data is available to be read from the Scanner.
  5104. ;
  5105. ;    Inputs:        Acc            =    Unspecified
  5106. ;                Y register    =    Unspecified
  5107. ;                X register    =    Unspecified
  5108. ;                P register    =    0=M=X=e
  5109. ;                Direct Page    =    Ours
  5110. ;                Data Bank    =    Ours
  5111. ;
  5112. ;    Outputs:    Acc            =    Error Code if any
  5113. ;                |sense_data    =    Data returned by the device
  5114. ;                Y register    =    Unspecified
  5115. ;                X register    =    Unspecified
  5116. ;                P register    =    0=M=X=e
  5117. ;                Direct Page    =    Ours
  5118. ;                Data Bank    =    Ours
  5119. ;
  5120. ;    Errors:        None.
  5121. ;
  5122. ;*******************************************************
  5123.  
  5124.                 EXPORT    get_data_status
  5125. get_data_status    PROC
  5126.  
  5127.  
  5128.                 lda        #null
  5129.                 clc
  5130.                 rts
  5131.  
  5132.                 ENDP
  5133.  
  5134.                 EJECT
  5135.  
  5136. ;____Dvc_Controls____
  5137. ;*******************************************************
  5138. ;
  5139. ;    'start_unit'
  5140. ;
  5141. ;    Issue a START UNIT Command to the target device
  5142. ;
  5143. ;    Inputs:        Acc            =    Unspecified
  5144. ;                Y register    =    Unspecified
  5145. ;                X register    =    Unspecified
  5146. ;                P register    =    0=M=X=e
  5147. ;                Direct Page    =    Ours
  5148. ;                Data Bank    =    Ours
  5149. ;
  5150. ;    Outputs:    Acc            =    Error Code if any
  5151. ;                Y register    =    Unspecified
  5152. ;                X register    =    Unspecified
  5153. ;                P register    =    0=M=X=e
  5154. ;                Direct Page    =    Ours
  5155. ;                Data Bank    =    Ours
  5156. ;
  5157. ;    Errors:        None
  5158. ;
  5159. ;*******************************************************
  5160.  
  5161.                 EXPORT    start_unit
  5162. start_unit        PROC
  5163.  
  5164. ;-------------------------------------------------------------------------------
  5165.  
  5166.                 IF            scsi_dtype = direct_acc    THEN
  5167.  
  5168.                 ldy        #dib.dvcchar
  5169.                 lda        [dib_ptr],y
  5170.                 and        #removable
  5171.                 bne        @do_it
  5172.                 rts
  5173.  
  5174. @do_it
  5175.  
  5176.                 ELSE
  5177.  
  5178. ;-------------------------------------------------------------------------------
  5179.  
  5180.                                         ;
  5181.                                         ; Set Stop Flag
  5182.                                         ;
  5183.                 lda        #$0001
  5184.                 tsb        |stop_bit
  5185.                 bra        start_stop
  5186.  
  5187.                 ENDIF
  5188.  
  5189. ;-------------------------------------------------------------------------------
  5190.  
  5191.                 EJECT
  5192.  
  5193. ;*******************************************************
  5194. ;
  5195. ;    'stop_unit'
  5196. ;
  5197. ;    Issue a STOP UNIT Command to the target device
  5198. ;
  5199. ;    Inputs:        Acc            =    Unspecified
  5200. ;                Y register    =    Unspecified
  5201. ;                X register    =    Unspecified
  5202. ;                P register    =    0=M=X=e
  5203. ;                Direct Page    =    Ours
  5204. ;                Data Bank    =    Ours
  5205. ;
  5206. ;    Outputs:    Acc            =    Error Code if any
  5207. ;                Y register    =    Unspecified
  5208. ;                X register    =    Unspecified
  5209. ;                P register    =    0=M=X=e
  5210. ;                Direct Page    =    Ours
  5211. ;                Data Bank    =    Ours
  5212. ;
  5213. ;    Errors:        None
  5214. ;
  5215. ;*******************************************************
  5216.  
  5217.                 EXPORT    stop_unit
  5218. stop_unit
  5219.  
  5220. ;-------------------------------------------------------------------------------
  5221.  
  5222.                 IF            scsi_dtype = direct_acc    THEN
  5223.  
  5224.                 ldy        #dib.dvcchar
  5225.                 lda        [dib_ptr],y
  5226.                 and        #removable
  5227.                 bne        @do_it
  5228.                 rts
  5229.  
  5230. @do_it
  5231.  
  5232.                 ELSE
  5233.  
  5234. ;-------------------------------------------------------------------------------
  5235.  
  5236.                                     ;
  5237.                                     ; Set Stop Flag
  5238.                                     ;
  5239.                 lda        #$0001
  5240.                 trb        |stop_bit
  5241.                                     ;
  5242.                                     ; Secondary entry point for START_UNIT
  5243.                                     ; Command
  5244.                                     ;
  5245.                 EXPORT    start_stop
  5246. start_stop
  5247.                                     ;
  5248.                                     ; Set Internal Command Flag
  5249.                                     ;
  5250.                 dec        |internal
  5251.                                     ;
  5252.                                     ; Set Parm Pointer.
  5253.                                     ;
  5254.                 lda        #@start_stop_p
  5255.                 sta        <scsi_mdrvr
  5256.                 lda        #^@start_stop_p
  5257.                 sta        <scsi_mdrvr+2
  5258.                                     ;
  5259.                                     ; Set IMMED Bit
  5260.                                     ;
  5261.                 lda        #immed_loc
  5262.                 tsb        @immed_loc
  5263.                                     ;
  5264.                                     ; It's a Control Call.
  5265.                                     ;
  5266.                 lda        #scsit_cont
  5267.                 sta        |call_type
  5268.                                     ;
  5269.                                     ; Issue the Call
  5270.                                     ;
  5271.                 jmp        |main_drvr
  5272.                                     ;
  5273.                                     ; Data for this call
  5274.                                     ; TEST UNIT READY Command Packet
  5275.                                     ;
  5276. @start_stop_p    dc.b    $1B            ;Command Number
  5277. @immed_loc        dc.b    $00            ;SCSI Command Flags
  5278.                 dcb.b    2,$00        ;Reserved
  5279.                 EXPORT    stop_bit
  5280. stop_bit        dc.b    $00            ;Start/Stop Bit
  5281.                 dc.b    $00            ;Vendor Unique
  5282.                 dcb.b    6,$00        ;Resrved
  5283.  
  5284.                 ENDIF
  5285.  
  5286. ;-------------------------------------------------------------------------------
  5287.  
  5288.                 ENDP
  5289.  
  5290.                 EJECT
  5291.  
  5292. ;*******************************************************
  5293. ;
  5294. ;    'SET 512 MODE'
  5295. ;
  5296. ;    This command is used to tell the device to set it's
  5297. ;    block size to 512 mode.  This is used for the CD-ROM
  5298. ;    Drives as well as any others that may need this
  5299. ;    function.
  5300. ;
  5301. ;    Inputs:        Acc            =    Unspecified
  5302. ;                Y register    =    Unspecified
  5303. ;                X register    =    Unspecified
  5304. ;                P register    =    0=M=X=e
  5305. ;                Direct Page    =    Ours
  5306. ;                Data Bank    =    Ours
  5307. ;
  5308. ;    Outputs:    Acc            =    Error Code if any
  5309. ;                Y register    =    Unspecified
  5310. ;                X register    =    Unspecified
  5311. ;                P register    =    0=M=X=e
  5312. ;                Direct Page    =    Ours
  5313. ;                Data Bank    =    Ours
  5314. ;
  5315. ;    Errors:        Carry set if call failed
  5316. ;
  5317. ;*******************************************************
  5318.  
  5319.                 EXPORT    set_512_mode
  5320. set_512_mode    PROC
  5321.  
  5322. ;-------------------------------------------------------------------------------
  5323.  
  5324.                 IF            block_dvc = true\
  5325.                 AND            character_dvc = false        THEN
  5326.                                         ;
  5327.                                         ; Set try twice flag.
  5328.                                         ;
  5329.                 dec        @try_twice
  5330.                                         ;
  5331.                                         ; Set Internal Command Flag
  5332.                                         ;
  5333.                 dec        |internal
  5334.                                         ;
  5335.                                         ; Set Parm length.
  5336.                                         ;
  5337.                 lda        #end_4_512-\
  5338.                         data_4_512
  5339.                 sta        <rqst_cnt
  5340.                 stz        <rqst_cnt+2
  5341.                                         ;
  5342.                                         ; Set Parm Pointer.
  5343.                                         ;
  5344. @try_again        lda        #@set_512_p
  5345.                 sta        <scsi_mdrvr
  5346.                 lda        #^@set_512_p
  5347.                 sta        <scsi_mdrvr+2
  5348.                                         ;
  5349.                                         ; Set Parm Pointer.
  5350.                                         ;
  5351.                 lda        #data_4_512
  5352.                 sta        <buff_ptr
  5353.                 lda        #^data_4_512
  5354.                 sta        <buff_ptr+2
  5355.                                         ;
  5356.                                         ; It's a Control Call.
  5357.                                         ;
  5358.                 lda        #scsit_cont
  5359.                 sta        |call_type
  5360.                                         ;
  5361.                                         ; Issue the Call
  5362.                                         ;
  5363.                 jsr        |main_drvr
  5364.                 bcc        @alles_klar
  5365.                                         ;
  5366.                                         ; Set Parm length.
  5367.                                         ;
  5368.                 lda        #$0000000c
  5369.                 sta        <rqst_cnt
  5370.                 stz        <rqst_cnt+2
  5371.  
  5372.                 inc        @try_twice
  5373.                 beq        @try_again
  5374.                                         ;
  5375.                                         ; Restore the values we destroyed
  5376.                                         ;
  5377. @alles_klar        stz        @try_twice
  5378.                 php
  5379.                 pha
  5380.                 jsr        set_our_dp
  5381.                 pla
  5382.                 plp
  5383.                 rts
  5384.                                         ;
  5385.                                         ; Data for this call
  5386.                                         ;
  5387. @try_twice        dc.w    null
  5388.                                         ;
  5389.                                         ; TEST UNIT READY Command Packet
  5390.                                         ;
  5391. @set_512_p        dc.b    $15                ;Command Number
  5392.  
  5393. ;-------------------------------------------------------------------------------
  5394.  
  5395.                 IF        scsi_dtype = direct_acc    THEN
  5396.                                         ;
  5397.                                         ; Set bit to save these values
  5398.                                         ;
  5399.                 dc.b    $01
  5400.  
  5401.                 ENDIF                    ;scsi_dtype = direct_acc
  5402.  
  5403. ;-------------------------------------------------------------------------------
  5404.  
  5405.                 IF        scsi_dtype = apple_cd    THEN
  5406.                                         ;
  5407.                                         ; Clear bit to save these values
  5408.                                         ;
  5409.                 dc.b    $00
  5410.  
  5411.                 ENDIF                    ;scsi_dtype = apple_cd
  5412.  
  5413. ;-------------------------------------------------------------------------------
  5414.  
  5415.                 dcb.b    3,$00            ;Reserved
  5416.                 dc.b    $00                ;Vendor Unique
  5417.                 dcb.b    6,$00            ;Resrved
  5418.                                         ;
  5419.                                         ; Data sent durring this call
  5420.                                         ;
  5421. data_4_512        dc.b    null
  5422.                 dc.b    $00
  5423.                 dc.b    null
  5424.                 dc.b    $08
  5425.                                         ;number of blocks
  5426.                 dc.b    null
  5427.                 dc.b    $00
  5428.                 dc.b    $00
  5429.                 dc.b    $00
  5430.                                         ;block size
  5431.                 dc.b    null
  5432.                 dc.b    $00
  5433.                 dc.b    $02
  5434.                 dc.b    $00
  5435.  
  5436. ;-------------------------------------------------------------------------------
  5437.  
  5438.                 IF        scsi_dtype = apple_cd    THEN
  5439.  
  5440. end_4_512
  5441.  
  5442.                 EXPORT        select_page_num
  5443. select_page_num    dc.b    $01                ;Page Number
  5444.                 dc.b    $06                ;Page Length
  5445.                 dc.b    $e4                ;Error Correction Flags
  5446.                 dc.b    $03                ;Retry Count
  5447.                 dc.b    $00                ;Correction Span
  5448.                 dc.b    $00                ;Head Offset Count
  5449.                 dc.b    $00                ;Data Strobe Offset
  5450.                 dc.b    $00                ;Recovery Time Limit
  5451.  
  5452.                 ELSE                    ;scsi_dtype = apple_cd
  5453.  
  5454. ;-------------------------------------------------------------------------------
  5455.  
  5456.                                         ;Page 1 Data
  5457.                 EXPORT        select_page_num
  5458. select_page_num    dc.b    $01                ;Page Number
  5459.                 dc.b    $06                ;Page Length
  5460.                 dc.b    $e4                ;Error Correction Flags
  5461.                 dc.b    $03                ;Retry Count
  5462.                 dc.b    $00                ;Correction Span
  5463.                 dc.b    $00                ;Head Offset Count
  5464.                 dc.b    $00                ;Data Strobe Offset
  5465.                 dc.b    $00                ;Recovery Time Limit
  5466. end_4_512
  5467.  
  5468.                 ENDIF                    ;scsi_dtype = apple_cd
  5469.  
  5470. ;-------------------------------------------------------------------------------
  5471.  
  5472.                 ELSE                    ;block_dvc = true
  5473.  
  5474. ;-------------------------------------------------------------------------------
  5475.  
  5476.                 lda        #null
  5477.                 clc
  5478.                 rts
  5479.  
  5480.                 ENDIF                    ;block_dvc = true
  5481.  
  5482. ;-------------------------------------------------------------------------------
  5483.  
  5484.                 ENDP
  5485.  
  5486.                 EJECT
  5487.  
  5488. ;____Evnt_Support____
  5489. ;*******************************************************
  5490. ;
  5491. ;    'notify_me'
  5492. ;
  5493. ;    This routine gets called by the SCSI Manager when
  5494. ;    some event occurs that is out of the ordinary.
  5495. ;
  5496. ;    Inputs:        None Yet
  5497. ;
  5498. ;    Outputs:    All Regs    =    Scrambled
  5499. ;
  5500. ;    Errors:        None Yet
  5501. ;
  5502. ;*******************************************************
  5503.  
  5504.                 EXPORT    notify_me
  5505. notify_me        PROC
  5506.                                         ;
  5507.                                         ; Vector for the SCSI Manager
  5508.                                         ; to call when an event occurs
  5509.                                         ; that affects my DIB
  5510.                                         ; structures.  This could be a
  5511.                                         ; new device online or media
  5512.                                         ; insertion.
  5513.                                         ;
  5514.                 clc                        ;Add CODE LATER
  5515.                 rtl
  5516.  
  5517.                 ENDP
  5518.  
  5519.                 EJECT
  5520.  
  5521. ;____Misc_Support____
  5522. ;*******************************************************
  5523. ;
  5524. ;    SET_DISK_SW
  5525. ;
  5526. ;    This routine checks the validity of the partition
  5527. ;    map block currently loaded in the internal buffer.
  5528. ;    This need only be called once per device.  If the
  5529. ;    map is valid, then the carry will be clear.  The 'Z'
  5530. ;    flag will also be set if this is not the first time
  5531. ;    that this routine was called for this device.  If
  5532. ;    the carry is set, then the map was invalid and the
  5533. ;    block count at 'T_DVC_BLOCKS' has been placed in the
  5534. ;    DIB pointed to by 'DIB_PTR'.  The starting block will
  5535. ;    also have been set to null.
  5536. ;
  5537. ;    Inputs:        <DIB_PTR        =    DIB Location
  5538. ;                Acc                =    Unspecified
  5539. ;                Y register        =    Unspecified
  5540. ;                X register        =    Unspecified
  5541. ;                P register        =    0=M=X=e
  5542. ;                Direct Page        =    Ours
  5543. ;                Data Bank        =    Ours
  5544. ;
  5545. ;    Outputs:    Acc                =    Unspecified
  5546. ;                Y register        =    Unspecified
  5547. ;                X register        =    Unspecified
  5548. ;                P register        =    0=M=X=e
  5549. ;                                =    Z = 0 if routine called before
  5550. ;                                =    C = 1 if not a partition map
  5551. ;                Direct Page        =    Ours
  5552. ;                Data Bank        =    Ours
  5553. ;
  5554. ;    Errors:        Only those allowed by the System Service
  5555. ;                Call SET_DISKSW.
  5556. ;
  5557. ;*******************************************************
  5558.  
  5559.                 EXPORT    set_disk_sw
  5560. set_disk_sw        PROC
  5561.  
  5562. ;-------------------------------------------------------------------------------
  5563.  
  5564.                 IF            block_dvc = true\
  5565.                 AND            character_dvc = false        THEN
  5566.                                         ;
  5567.                                         ; Check the removable flag.  If the media
  5568.                                         ; is removable, then we will only set the
  5569.                                         ; switch flag and let the status calls do
  5570.                                         ; their thing before this device goes
  5571.                                         ; online.  If it is non-removable, then
  5572.                                         ; we need to say that the device is
  5573.                                         ; switched, but also set the online bits.
  5574.                                         ;
  5575.                 ldy        #dib.dvcchar
  5576.                 lda        [dib_ptr],y
  5577.                 and        #removable
  5578.                 beq        @non_removable
  5579.                                         ;
  5580.                                         ; Set the Disk Switched Bit in Status.
  5581.                                         ;
  5582.                 ldy        #dib.dvcflag
  5583.                 lda        [dib_ptr],y
  5584.                 ora        #dvc_switch
  5585.                 sta        [dib_ptr],y
  5586.                 bra        @over1
  5587.                                         ;
  5588.                                         ; Set the Disk Online Bit in Status.
  5589.                                         ;
  5590. @non_removable    ldy        #dib.dvcflag
  5591.                 lda        [dib_ptr],y
  5592.                 and        #$ffff--\
  5593.                         dvc_switch--\
  5594.                         dvc_hardofl
  5595.                 ora        #dvc_online
  5596.                 sta        [dib_ptr],y
  5597.                                         ;
  5598.                                         ; Preserve the World from this.
  5599.                                         ;
  5600. @over1            ldx        |gsos_dpage
  5601.  
  5602.                 lda        >dev_num,x
  5603.                 pha
  5604.                 lda        >dib_ptr,x
  5605.                 pha
  5606.                 lda        >dib_ptr+2,x
  5607.                 pha
  5608.                 lda        <dev_num
  5609.                 sta        >dev_num,x
  5610.                 lda        <dib_ptr
  5611.                 sta        >dib_ptr,x
  5612.                 lda        <dib_ptr+2
  5613.                 sta        >dib_ptr+2,x
  5614.  
  5615.                 txa
  5616.                 tcd
  5617.  
  5618.                 jsl        set_disksw
  5619.                 tay
  5620.  
  5621.                 lda        |direct_page
  5622.                 tcd
  5623.  
  5624.                 ldx        |gsos_dpage
  5625.                 pla
  5626.                 sta        >dib_ptr+2,x
  5627.                 pla
  5628.                 sta        >dib_ptr,x
  5629.                 pla
  5630.                 sta        >dev_num,x
  5631.  
  5632.                 tya
  5633.                 cmp        #$0001
  5634.                 rts
  5635.  
  5636.                 ELSE
  5637.  
  5638. ;-------------------------------------------------------------------------------
  5639.  
  5640.                 lda        #null
  5641.                 clc
  5642.                 rts
  5643.  
  5644.                 ENDIF
  5645.  
  5646. ;-------------------------------------------------------------------------------
  5647.  
  5648.                 ENDP
  5649.  
  5650.                 EJECT
  5651.  
  5652. ;*******************************************************
  5653. ;
  5654. ;    TRASH_VOLUME
  5655. ;
  5656. ;    This routine write a non-formatted pattern to block
  5657. ;    2 of the volume whose DIB is [dib_ptr].  This is to
  5658. ;    force the OS to re-format or lay down the OS data for
  5659. ;    that volume rather than using what is already there
  5660. ;    and appears to be valid.
  5661. ;
  5662. ;    Inputs:        <DIB_PTR        =    DIB Location
  5663. ;                |trash_it        =    Boolean
  5664. ;                            0    =    Trash the Volume
  5665. ;                Acc                =    Unspecified
  5666. ;                Y register        =    Unspecified
  5667. ;                X register        =    Unspecified
  5668. ;                P register        =    0=M=X=e
  5669. ;                Direct Page        =    Ours
  5670. ;                Data Bank        =    Ours
  5671. ;
  5672. ;    Outputs:    Acc                =    Unspecified
  5673. ;                Y register        =    Unspecified
  5674. ;                X register        =    Unspecified
  5675. ;                P register        =    0=M=X=e
  5676. ;                Direct Page        =    Ours
  5677. ;                Data Bank        =    Ours
  5678. ;
  5679. ;    Errors:        Better be none.
  5680. ;
  5681. ;*******************************************************
  5682.  
  5683.                 EXPORT    trash_volume
  5684. trash_volume    PROC
  5685.  
  5686. ;-------------------------------------------------------------------------------
  5687.  
  5688.                 IF            scsi_dtype = direct_acc    THEN
  5689.  
  5690.                                         ;
  5691.                                         ; Should we really trash the volume?
  5692.                                         ;
  5693.                 lda        |trash_it
  5694.                 beq        @dont_trash
  5695.                                         ;
  5696.                                         ; Set Main Driver Pointer to
  5697.                                         ; our data for the command.
  5698.                                         ;
  5699.                 lda        #@cmd_$800A
  5700.                 sta        <scsi_mdrvr
  5701.                 lda        #^@cmd_$800A
  5702.                 sta        <scsi_mdrvr+2
  5703.                                         ;
  5704.                                         ; Set our buffer Pointer to
  5705.                                         ; our data for the command.
  5706.                                         ;
  5707.                 lda        #@destructo_data
  5708.                 sta        <buff_ptr
  5709.                 lda        #^@destructo_data
  5710.                 sta        <buff_ptr+2
  5711.                                         ;
  5712.                                         ; Set length of our data for the
  5713.                                         ; command.
  5714.                                         ;
  5715.                 lda        #block_size
  5716.                 sta        <rqst_cnt
  5717.                 stz        <rqst_cnt+2
  5718.                                         ;
  5719.                                         ; Call Main Driver
  5720.                                         ;
  5721.                 lda        #scsit_cont
  5722.                 sta        |call_type
  5723.                                         ;
  5724.                                         ; Issue the call.
  5725.                                         ;
  5726.                 jsr        check_532_rw
  5727.  
  5728. @dont_trash        rts
  5729.  
  5730.                                         ;
  5731.                                         ; Command Data for this call.
  5732.                                         ;
  5733. @cmd_$800A        dc.b    $0A
  5734.                 dc.b    $00
  5735.                 dc.w    $0002
  5736.                 dc.b    $01
  5737.                 dcb.b    7,$00
  5738.  
  5739. @destructo_data    dcb.b    512,$6c
  5740.  
  5741.                 ELSE
  5742.  
  5743. ;-------------------------------------------------------------------------------
  5744.  
  5745.                 lda        #null
  5746.                 clc
  5747.                 rts
  5748.  
  5749.                 ENDIF
  5750.  
  5751. ;-------------------------------------------------------------------------------
  5752.  
  5753.                 ENDP
  5754.  
  5755.                 EJECT
  5756.  
  5757. ;*******************************************************
  5758. ;
  5759. ;    'SAVE_DP'
  5760. ;
  5761. ;    This routine is only called durring the initial
  5762. ;    startup.  It saves away the current values on GS/OS
  5763. ;    Direct Page so that we can use the space until we
  5764. ;    have our own Direct Page.
  5765. ;
  5766. ;    Inputs:        Acc            =    Unspecified
  5767. ;                Y register    =    Unspecified
  5768. ;                X register    =    Unspecified
  5769. ;                P register    =    0=M=X=e
  5770. ;                Direct Page    =    GS/OS
  5771. ;                Data Bank    =    Ours
  5772. ;
  5773. ;    Outputs:    Acc            =    Unspecified
  5774. ;                Y register    =    Unspecified
  5775. ;                X register    =    Unspecified
  5776. ;                P register    =    0=M=X=e
  5777. ;                Direct Page    =    GS/OS
  5778. ;                Data Bank    =    Ours
  5779. ;
  5780. ;    Errors:        None.
  5781. ;
  5782. ;*******************************************************
  5783.  
  5784.                 EXPORT    save_dp
  5785. save_dp            PROC
  5786.                                             ;
  5787.                                             ; Check to see if this call was
  5788.                                             ; nested.
  5789.                                             ;
  5790.                 lda        |valid
  5791.                 bne        @exit
  5792.                                             ;
  5793.                                             ; Calculate Source Address.
  5794.                                             ;
  5795.                 clc
  5796.                 lda        |gsos_dpage
  5797.                 adc        #start_our_zp
  5798.                 pea        $0000
  5799.                 pha
  5800.                                             ;
  5801.                                             ; Destination Address of temporary
  5802.                                             ; storage
  5803.                                             ;
  5804.                 pushlong    #saved_zp
  5805.                 
  5806.                 pushlong    #end_our_zp-\    ;Length of the move
  5807.                             start_our_zp
  5808.                 
  5809.                 pushword    #move_sinc_dinc
  5810.  
  5811.                 jsl        move_info            ;Move the data
  5812.  
  5813.                 dec        |valid
  5814.  
  5815. @exit            rts
  5816.  
  5817.                 ENDP
  5818.  
  5819.                 EJECT
  5820.  
  5821. ;*******************************************************
  5822. ;
  5823. ;    Move the contents of the first $20 bytes of GS/OS
  5824. ;    Direct Page to our Direct Page.
  5825. ;
  5826. ;    Inputs:        Acc            =    Unspecified
  5827. ;                Y register    =    Unspecified
  5828. ;                X register    =    Unspecified
  5829. ;                P register    =    0=M=X=e
  5830. ;                Direct Page    =    Ours
  5831. ;                Data Bank    =    Ours
  5832. ;
  5833. ;    Outputs:    Acc            =    Unspecified
  5834. ;                Y register    =    Unspecified
  5835. ;                X register    =    Unspecified
  5836. ;                P register    =    0=M=X=e
  5837. ;                Direct Page    =    Ours
  5838. ;                Data Bank    =    Ours
  5839. ;
  5840. ;    Errors:        Carry set if Unit is not the only
  5841. ;                device in this linke that is still
  5842. ;                online.
  5843. ;
  5844. ;*******************************************************
  5845.  
  5846.                 EXPORT    restore_dp
  5847. restore_dp        PROC
  5848.                                             ;
  5849.                                             ; Check to see if this call was
  5850.                                             ; nested.
  5851.                                             ;
  5852.                 lda        |valid
  5853.                 beq        @exit
  5854.                                             ;
  5855.                                             ; Source Address of temporary
  5856.                                             ; storage
  5857.                                             ;
  5858.                 pushlong    #saved_zp
  5859.                                             ;
  5860.                                             ; Calculate Destination Address.
  5861.                                             ;
  5862.                 clc
  5863.                 lda        |gsos_dpage
  5864.                 adc        #start_our_zp
  5865.                 pea        $0000
  5866.                 pha
  5867.                 
  5868.                 pushlong    #end_our_zp-\    ;Length of the move
  5869.                             start_our_zp
  5870.                 
  5871.                 pushword    #move_sinc_dinc
  5872.  
  5873.                 jsl        move_info            ;Move the data
  5874.  
  5875.                 stz        |valid
  5876.  
  5877. @exit            rts
  5878.  
  5879.                 ENDP
  5880.  
  5881.                 EJECT
  5882.  
  5883. ;*******************************************************
  5884. ;
  5885. ;    Move the contents of the first $20 bytes of GS/OS
  5886. ;    Direct Page to our Direct Page.
  5887. ;
  5888. ;    Inputs:        Acc            =    Unspecified
  5889. ;                Y register    =    Unspecified
  5890. ;                X register    =    Unspecified
  5891. ;                P register    =    0=M=X=e
  5892. ;                Direct Page    =    Ours
  5893. ;                Data Bank    =    Ours
  5894. ;
  5895. ;    Outputs:    Acc            =    Unspecified
  5896. ;                Y register    =    Unspecified
  5897. ;                X register    =    Unspecified
  5898. ;                P register    =    0=M=X=e
  5899. ;                Direct Page    =    Ours
  5900. ;                Data Bank    =    Ours
  5901. ;
  5902. ;    Errors:        Carry set if Unit is not the only
  5903. ;                device in this linke that is still
  5904. ;                online.
  5905. ;
  5906. ;*******************************************************
  5907.  
  5908.                 EXPORT    set_our_dp
  5909. set_our_dp        PROC
  5910.                                         ;
  5911.                                         ; Calculate Source Address.
  5912.                                         ;
  5913.                 clc
  5914.                 lda        |gsos_dpage
  5915.                 adc        #dev_num
  5916.                 pea        $0000
  5917.                 pha
  5918.                                         ;
  5919.                                         ; Calculate Destination Address of
  5920.                                         ; our Direct Page that we want.
  5921.                                         ;
  5922.                 clc
  5923.                 lda        |direct_page
  5924.                 adc        #dev_num
  5925.                 pea        $0000
  5926.                 pha
  5927.                 
  5928.                 pushlong    #dib_ptr+4    ;Length of the move
  5929.                 
  5930.                 pushword    #move_sinc_dinc
  5931.  
  5932.                 jsl        move_info        ;Move the data
  5933.                 rts
  5934.                 ENDP
  5935.  
  5936.                 EJECT
  5937.  
  5938. ;*******************************************************
  5939. ;
  5940. ;    'check_532_rw'
  5941. ;
  5942. ;    There are a few drives that have been formated with
  5943. ;    512 ($214) bytes per block.  These devices work
  5944. ;    perfectly fine in single block I/O, padding the end
  5945. ;    with 20 bytes in a write, or stripping them for a
  5946. ;    read, but when doing a multi-block transaction we
  5947. ;    need to account for the 20 bytes between the end of
  5948. ;    real data for this block and the beginning of the
  5949. ;    next block.  Because of this, we will need to build
  5950. ;    a data chaining structure that will read or write
  5951. ;    512 bytes of data to the users buffer, followed by
  5952. ;    20 bytes read or written to ROM space.  Doing this
  5953. ;    will hinder performance and will prevent caching
  5954. ;    from working.  If these are important to the user,
  5955. ;    they can reformat their drive.
  5956. ;
  5957. ;    This routine is called in place of calling the Main
  5958. ;    Driver.  It decides if the call should go via the
  5959. ;    normal or 532 method.  All Inputs, Outputs and Setup
  5960. ;    Structures are the same.
  5961. ;
  5962. ;    Inputs:        Acc            =    Unspecified
  5963. ;                Y register    =    Unspecified
  5964. ;                X register    =    Unspecified
  5965. ;                P register    =    0=M=X=e
  5966. ;                Direct Page    =    Ours
  5967. ;                Data Bank    =    Ours
  5968. ;
  5969. ;    Outputs:    Acc            =    Unspecified
  5970. ;                Y register    =    Unspecified
  5971. ;                X register    =    Unspecified
  5972. ;                P register    =    0=M=X=e
  5973. ;                Direct Page    =    GS/OS Direct Page
  5974. ;                Data Bank    =    Ours
  5975. ;
  5976. ;    Errors:        None
  5977. ;
  5978. ;*******************************************************
  5979.  
  5980.                 EXPORT    check_532_rw
  5981. check_532_rw    PROC
  5982.  
  5983. ;-------------------------------------------------------------------------------
  5984.  
  5985.                 IF            scsi_dtype = direct_acc    THEN
  5986.  
  5987.                                         ;
  5988.                                         ; Check for 532 byte block.
  5989.                                         ;
  5990.                 ldy        #dib.blksize
  5991.                 lda        [dib_ptr],y
  5992.                 cmp        #$214
  5993.                 beq        @do_532
  5994.                 jmp        |main_drvr
  5995.  
  5996. @do_532            jmp        munge_532
  5997.  
  5998. ;-------------------------------------------------------------------------------
  5999.  
  6000.                 ELSE
  6001.  
  6002.                 jmp        |main_drvr
  6003.  
  6004.                 ENDIF
  6005.  
  6006. ;-------------------------------------------------------------------------------
  6007.  
  6008.                 ENDP
  6009.  
  6010.                 EJECT
  6011.  
  6012. ;*******************************************************
  6013. ;
  6014. ;    'munge_532'
  6015. ;
  6016. ;    There are a few drives that have been formated with
  6017. ;    512 ($214) bytes per block.  These devices work
  6018. ;    perfectly fine in single block I/O, padding the end
  6019. ;    with 20 bytes in a write, or stripping them for a
  6020. ;    read, but when doing a multi-block transaction we
  6021. ;    need to account for the 20 bytes between the end of
  6022. ;    real data for this block and the beginning of the
  6023. ;    next block.  Because of this, we will need to build
  6024. ;    a data chaining structure that will read or write
  6025. ;    512 bytes of data to the users buffer, followed by
  6026. ;    20 bytes read or written to ROM space.  Doing this
  6027. ;    will hinder performance and will prevent caching
  6028. ;    from working.  If these are important to the user,
  6029. ;    they can reformat their drive.
  6030. ;
  6031. ;    This routine is called in place of calling the Main
  6032. ;    Driver.  All Inputs, Outputs and Setup Structures
  6033. ;    are the same.
  6034. ;
  6035. ;    Inputs:        Acc            =    Unspecified
  6036. ;                Y register    =    Unspecified
  6037. ;                X register    =    Unspecified
  6038. ;                P register    =    0=M=X=e
  6039. ;                Direct Page    =    Ours
  6040. ;                Data Bank    =    Ours
  6041. ;
  6042. ;    Outputs:    Acc            =    Unspecified
  6043. ;                Y register    =    Unspecified
  6044. ;                X register    =    Unspecified
  6045. ;                P register    =    0=M=X=e
  6046. ;                Direct Page    =    GS/OS Direct Page
  6047. ;                Data Bank    =    Ours
  6048. ;
  6049. ;    Errors:        None
  6050. ;
  6051. ;*******************************************************
  6052.  
  6053.                 EXPORT    munge_532
  6054. munge_532        PROC
  6055.  
  6056. ;-------------------------------------------------------------------------------
  6057.  
  6058.                 IF            scsi_dtype = direct_acc    THEN
  6059.  
  6060.                                         ;
  6061.                                         ; Set User's buffer location
  6062.                                         ;
  6063.                 lda        <buff_ptr
  6064.                 sta        |@User_buff
  6065.                 lda        <buff_ptr+2
  6066.                 sta        |@User_buff+2
  6067.                                         ;
  6068.                                         ; Generate a block count.
  6069.                                         ;
  6070.                 stz        @block_cnt
  6071.                 lda        <rqst_cnt+2
  6072.                 sta        @block_cnt+1
  6073.                 lda        <rqst_cnt
  6074.                 and        #$fe00
  6075.                 cmp        <rqst_cnt
  6076.                 beq        @equal_512
  6077.  
  6078.                 lda        #drvr_bad_cnt
  6079.                 sec
  6080.                 rts
  6081.  
  6082. @equal_512        lsr        @block_cnt+1
  6083.                 ror        a
  6084.                 tsb        @block_cnt-1
  6085.                                         ;
  6086.                                         ; Adjust users request cnt to reflect
  6087.                                         ; that there are 20 bytes/block more
  6088.                                         ; to transfer than the user requested.
  6089.                                         ; This is done by multiplying the block
  6090.                                         ; count that we just calculated bu $14.
  6091.                                         ;
  6092.                                         ; First preserve the old value.
  6093.                                         ;
  6094.                 lda        <rqst_cnt+2
  6095.                 sta        @rqst_cnt+2
  6096.                 lda        <rqst_cnt
  6097.                 sta        @rqst_cnt
  6098.                                         ;
  6099.                                         ; Now adjust count.
  6100.                                         ;
  6101.                 lda        @block_cnt+2
  6102.                 sta        |scratch0+2
  6103.                 lda        @block_cnt
  6104.                 sta        |scratch0
  6105.                                         ;
  6106.                                         ; x4 first
  6107.                                         ;
  6108.                 asl        |scratch0        ;x2
  6109.                 asl        |scratch0+2
  6110.  
  6111.                 asl        |scratch0        ;x2 (x4)
  6112.                 asl        |scratch0+2
  6113.                                         ;
  6114.                                         ; Save the x4.
  6115.                                         ;
  6116.                 lda        |scratch0
  6117.                 sta        |scratch2
  6118.                 lda        |scratch0+2
  6119.                 sta        |scratch2+2
  6120.                                         ;
  6121.                                         ; Finish the x16
  6122.                                         ;
  6123.                 asl        |scratch0        ;x2 (x8)
  6124.                 asl        |scratch0+2
  6125.  
  6126.                 asl        |scratch0        ;x2 (x16)
  6127.                 asl        |scratch0+2
  6128.                                         ;
  6129.                                         ; Add the x4 to x16 for x20
  6130.                                         ;
  6131.                 clc
  6132.                 lda        |scratch0
  6133.                 adc        |scratch2
  6134.                 sta        |scratch0
  6135.                 lda        |scratch0+2
  6136.                 adc        |scratch2+2
  6137.                 sta        |scratch0+2
  6138.                                         ;
  6139.                                         ; Add the x20 to the original
  6140.                                         ; request count.
  6141.                                         ;
  6142.                 clc
  6143.                 lda        |scratch0
  6144.                 adc        <rqst_cnt
  6145.                 sta        <rqst_cnt
  6146.                 lda        |scratch0+2
  6147.                 adc        <rqst_cnt+2
  6148.                 sta        <rqst_cnt+2
  6149.                                         ;
  6150.                                         ; Preserve the data pointer currently
  6151.                                         ; used in the DIB and replace it with
  6152.                                         ; a pointer to our 532 byte block
  6153.                                         ; Data Chaining instructions.
  6154.                                         ;
  6155.                 clc
  6156.                 ldy        #dib.trx_ptr
  6157.                 lda        [dib_ptr],y
  6158.                 sta        |dib_data_struct
  6159.  
  6160.                 lda        #@munger_DC
  6161.                 sta        [dib_ptr],y
  6162.  
  6163.                 ldy        #dib.trx_ptr+2
  6164.                 lda        [dib_ptr],y
  6165.                 sta        |dib_data_struct+2
  6166.  
  6167.                 lda        #^@munger_DC
  6168.                 sta        [dib_ptr],y
  6169.                                         ;
  6170.                                         ; Preserve the Block size and replace
  6171.                                         ; it with $0214
  6172.                                         ;
  6173.                 lda        <blk_size
  6174.                 sta        @blk_size
  6175.                 lda        #$0214
  6176.                 sta        <blk_size
  6177.                                         ;
  6178.                                         ; Issue the call.
  6179.                                         ;
  6180.                 jsr        |main_drvr
  6181.                                         ;
  6182.                                         ; Preserve the result.
  6183.                                         ;
  6184.                 pha
  6185.                 php
  6186.                                         ;
  6187.                                         ; Restore the Block size.
  6188.                                         ;
  6189.                 lda        @blk_size
  6190.                 sta        <blk_size
  6191.                                         ;
  6192.                                         ; Restore DIB's data pointer.
  6193.                                         ;
  6194.  
  6195.                 ldy        #dib.trx_ptr
  6196.                 lda        |dib_data_struct
  6197.                 sta        [dib_ptr],y
  6198.  
  6199.                 ldy        #dib.trx_ptr+2
  6200.                 lda        |dib_data_struct+2
  6201.                 sta        [dib_ptr],y
  6202.                                         ;
  6203.                                         ; Restore the original request count.
  6204.                                         ;
  6205.                 lda        @rqst_cnt+2
  6206.                 sta        <rqst_cnt+2
  6207.                 lda        @rqst_cnt
  6208.                 sta        <rqst_cnt
  6209.                                         ;
  6210.                                         ; Restore state of the call's exit.
  6211.                                         ;
  6212.                 plp
  6213.                 pla
  6214.                                         ;
  6215.                                         ; Exit.
  6216.                                         ;
  6217.                 rts
  6218.                                         ;
  6219.                                         ; Temp Storage area.
  6220.                                         ;
  6221. @rqst_cnt        dc.l    null
  6222. @blk_size        dc.w    null
  6223.  
  6224. @munger_DC                                ;
  6225.                                         ; Data Chaining Structure.
  6226.                                         ;
  6227. @User_buff        dc.l    $00000000        ;Users Buffer Space
  6228.                 dc.l    $00000200        ;Request Count
  6229.                 dc.l    $00000200        ;Add to buffer at each pass
  6230.                 dc.l    $00000000        ;Reserved.
  6231.  
  6232.                 dc.l    $00ff0600        ;Location for spare bytes (ROM)
  6233.                 dc.l    $00000014        ;Number of bogus bytes
  6234.                 dc.l    $00000000        ;Leave buffer pointer alone
  6235.                 dc.l    $00000000        ;Reserved.
  6236.  
  6237.                 dc.l    $ffffffff        ;Looping Command
  6238. @block_cnt        dc.l    $00000000        ;Block Count
  6239.                 dc.l    $00000000-2        ;Go Back 2 commands
  6240.                 dc.l    $00000000        ;Reserved
  6241.  
  6242.                 dc.l    $00000000        ;DCStop Command
  6243.                 dc.l    $00000000        ;DCStop Command
  6244.                 dc.l    $00000000        ;DCStop Command
  6245.                 dc.l    $00000000        ;DCStop Command
  6246.  
  6247.                 dc.l    $00000000        ;Safety space
  6248.  
  6249. ;-------------------------------------------------------------------------------
  6250.  
  6251.                 ELSE
  6252.  
  6253.                 lda        #null
  6254.                 clc
  6255.                 rts
  6256.  
  6257.                 ENDIF
  6258.  
  6259. ;-------------------------------------------------------------------------------
  6260.  
  6261.                 ENDP
  6262.  
  6263.                 EJECT
  6264.  
  6265. ;*******************************************************
  6266. ;
  6267. ;    'divide'
  6268. ;
  6269. ;    This routine divides a 16 bit number stored in
  6270. ;    'divsor' into the 32 bit number stored in 'divend'.
  6271. ;    The result will be in 'result' if no error occured.
  6272. ;    If 'divend' is not an integral multiple of 'divsor'
  6273. ;    an error will be returned.
  6274. ;
  6275. ;    Inputs:        'divsor'        =    16 bit number
  6276. ;                'divend'        =    32 bit number
  6277. ;                'max_blk_cnt'    =    Max Result Allowed
  6278. ;                Acc                =    Unspecified
  6279. ;                Y register        =    Unspecified
  6280. ;                X register        =    Unspecified
  6281. ;                P register        =    0=M=X=e
  6282. ;                Direct Page        =    GS/OS Direct Page
  6283. ;                Data Bank        =    Ours
  6284. ;
  6285. ;    Outputs:    'result'        =    result of division
  6286. ;                Acc                =    Error Code if Carry Set
  6287. ;                'max_blk_cnt'    =    null if no error
  6288. ;                                    Intact if an error is returned
  6289. ;                Y register        =    Unspecified
  6290. ;                X register        =    Unspecified
  6291. ;                P register        =    0=M=X=e
  6292. ;                Direct Page        =    GS/OS Direct Page
  6293. ;                Data Bank        =    Ours
  6294. ;
  6295. ;    Errors:        Carry set if non-integral result
  6296. ;
  6297. ;*******************************************************
  6298.  
  6299.                 EXPORT    divide
  6300. divide            PROC
  6301.  
  6302. ;-------------------------------------------------------------------------------
  6303.  
  6304.                 IF            block_dvc = true\
  6305.                 AND            character_dvc = false        THEN
  6306.                                                 ;
  6307.                                                 ; Clear Result field
  6308.                                                 ;
  6309.                 stz        |result
  6310.                 stz        |result+2
  6311.                                                 ;
  6312.                                                 ; 32 bits in result.
  6313.                                                 ;
  6314.                 ldx        #32-1
  6315.                                                 ;
  6316.                                                 ; Make 'divsor' an odd value.
  6317.                                                 ; This is nothing more than
  6318.                                                 ; deviding both numbers by 16
  6319.                                                 ; until 'divsor' is an odd value.
  6320.                                                 ; If any bits roll out of 'divend'
  6321.                                                 ; then this was an incorrect call.
  6322.                                                 ;
  6323. @div16_loop        lda        |divsor
  6324.                 cmp        #block_size                ;Special Case /block_size
  6325.                 bne        @not_512
  6326.                 lda        |divend
  6327.                 and        #block_size-1
  6328.                 bne        @error
  6329.  
  6330. ;-------------------------------------------------------------------------------
  6331.  
  6332.                 IF            scsi_dtype = direct_acc    THEN
  6333.                                                 ;
  6334.                                                 ; Quick Divide by block_size
  6335.                                                 ;
  6336.                 lda        |divend+3
  6337.                 and        #$00ff
  6338.                 lsr        a
  6339.                 sta        |result+2
  6340.  
  6341.                 lda        |divend+1
  6342.                 ror        a
  6343.                 sta        |result
  6344.  
  6345.                 jmp        @chk_rslt
  6346.  
  6347.                 ENDIF
  6348.  
  6349. ;-------------------------------------------------------------------------------
  6350.  
  6351.                 IF            scsi_dtype = apple_cd    THEN
  6352.                                                 ;
  6353.                                                 ; Quick Divide by $0200
  6354.                                                 ;
  6355.                 lda        |divend+3
  6356.                 and        #$00ff
  6357.                 lsr        a
  6358.                 sta        |result+2
  6359.  
  6360.                 lda        |divend+1
  6361.                 ror        a
  6362.                 sta        |result
  6363.  
  6364.                 jmp        @chk_rslt
  6365.  
  6366.                 ENDIF
  6367.  
  6368. ;-------------------------------------------------------------------------------
  6369.  
  6370. @not_512        and        #bit_0
  6371.                 bne        @do_divide
  6372.                 lsr        |divsor
  6373.                 lsr        |divend+2
  6374.                 ror        |divend
  6375.                 bcc        @div16_loop
  6376.                 bra        @error
  6377.                                                 ;
  6378.                                                 ; Main division loop.  We will
  6379.                                                 ; continue to divide the divsor
  6380.                                                 ; by 16 until finished.  Each
  6381.                                                 ; time that divsor becomes odd,
  6382.                                                 ; we will subtract divend and
  6383.                                                 ; roll a bit into the high end
  6384.                                                 ; of result.
  6385.                                                 ;
  6386. @do_divide        lda        |divend
  6387.                 and        #bit_0
  6388.                 clc                                ;We must clear the carry incase
  6389.                 beq        @do_div16                ;the branch is taken.
  6390.                                                 ;
  6391.                                                 ; We are odd. Do the subtraction.
  6392.                                                 ;
  6393.                 sec
  6394.                 lda        |divend
  6395.                 sbc        |divsor
  6396.                 sta        |divend
  6397.                 lda        |divend+2
  6398.                 sbc        #$0000
  6399.                 sta        |divend+2
  6400.                 bcc        @error                    ;If this is taken, bad data.
  6401.                                                 ;
  6402.                                                 ; Divide both the divsor and 
  6403.                                                 ; results by 16.  The carry will
  6404.                                                 ; roll into the reult from the
  6405.                                                 ; high bit end.
  6406.                                                 ;
  6407. @do_div16        php
  6408.                 lsr        |divend+2
  6409.                 ror        |divend
  6410.                 plp
  6411. @clean_up        ror        |result+2
  6412.                 ror        |result
  6413.                                                 ;
  6414.                                                 ; Have we done 32 bits yet?
  6415.                                                 ;
  6416.                 dex
  6417.                 bmi        @chk_rslt                ;Yes.
  6418.                                                 ;
  6419.                                                 ; No we havent.  If divsor is
  6420.                                                 ; non-zero then do next itteration.
  6421.                                                 ; If it is = zero then clean up
  6422.                                                 ; result and exit.
  6423.                                                 ;
  6424.                 lda        |divend+2
  6425.                 ora        |divend
  6426.                 bne        @do_divide
  6427.                                                 ;
  6428.                                                 ; Clean up Result.
  6429.                                                 ;
  6430.                 clc
  6431.                 bra        @clean_up
  6432.                                                 ;
  6433.                                                 ; Here for bcs offset.
  6434.                                                 ;
  6435. @error            sec
  6436.                 lda        #drvr_bad_cnt
  6437.                 rts
  6438.                                                 ;
  6439.                                                 ; Check to see if the result is within
  6440.                                                 ; the max.
  6441.                                                 ;
  6442. @chk_rslt        lda        |max_blk_cnt
  6443.                 ora        |max_blk_cnt+2
  6444.                 beq        @out
  6445.  
  6446.                 sec
  6447.                 lda        |max_blk_cnt
  6448.                 sbc        |result
  6449.                 sta        @temp
  6450.                 lda        |max_blk_cnt+2
  6451.                 sbc        |result+2
  6452.                 bge        @clean
  6453.                                                 ;
  6454.                                                 ; Exit
  6455.                                                 ;
  6456.                 sec
  6457.                 lda        #drvr_bad_parm
  6458.                 rts
  6459.  
  6460. @clean            stz        |max_blk_cnt
  6461.                 stz        |max_blk_cnt+2
  6462. @out            clc
  6463.                 rts
  6464.                                                     ;
  6465.                                                     ; Data Area.
  6466.                                                     ;
  6467. @temp            dc.w    null
  6468.  
  6469.                 ELSE
  6470.  
  6471. ;-------------------------------------------------------------------------------
  6472.  
  6473.                 lda        #null
  6474.                 clc
  6475.                 rts
  6476.  
  6477.                 ENDIF
  6478.  
  6479. ;-------------------------------------------------------------------------------
  6480.  
  6481.                 ENDP
  6482.  
  6483.                 EJECT
  6484.  
  6485. ;*******************************************************
  6486. ;
  6487. ;    'calc_bytes'
  6488. ;
  6489. ;    This routine Multiplies a 16 bit number stored in
  6490. ;    'm_blk_size' by a 32 bit number stored in 'm_blk_cnt'.
  6491. ;    The result will be in 'm_rslt'.
  6492. ;
  6493. ;    Inputs:        'm_blk_size'=    16 bit Block Size
  6494. ;                'm_blk_cnt'    =    32 bit Block Count
  6495. ;                Acc            =    Unspecified
  6496. ;                Y register    =    Unspecified
  6497. ;                X register    =    Unspecified
  6498. ;                P register    =    0=M=X=e
  6499. ;                Direct Page    =    GS/OS Direct Page
  6500. ;                Data Bank    =    Ours
  6501. ;
  6502. ;    Outputs:    'm_rslt'    =    result of division
  6503. ;                Acc            =    Unspecified
  6504. ;                Y register    =    Unspecified
  6505. ;                X register    =    Unspecified
  6506. ;                P register    =    0=M=X=e
  6507. ;                Direct Page    =    GS/OS Direct Page
  6508. ;                Data Bank    =    Ours
  6509. ;
  6510. ;    Errors:        None
  6511. ;
  6512. ;*******************************************************
  6513.  
  6514.                 EXPORT    calc_bytes
  6515. calc_bytes        PROC
  6516.  
  6517. ;-------------------------------------------------------------------------------
  6518.  
  6519.                 IF            block_dvc = true\
  6520.                 AND            character_dvc = false        THEN
  6521.                                             ;
  6522.                                             ; Clear Result field
  6523.                                             ;
  6524.                 stz        |m_rslt
  6525.                 stz        |m_rslt+2
  6526.                                             ;
  6527.                                             ; Check 'm_blk_size' against the block
  6528.                                             ; size for this device.  If it is Equal,
  6529.                                             ; the do cheap processing.  Otherwise do
  6530.                                             ; full multiply logic.
  6531.                                             ;
  6532. @div16_loop        lda        |m_blk_size
  6533.                 cmp        #block_size            ;Special Case *block_size
  6534.                 bne        @not_512
  6535.  
  6536. ;-------------------------------------------------------------------------------
  6537.  
  6538.                 IF            scsi_dtype = direct_acc    THEN
  6539.                                             ;
  6540.                                             ; Quick Multiply by $0200
  6541.                                             ;
  6542.                 lda        |m_blk_cnt
  6543.                 asl        a
  6544.                 sta        |m_rslt+1
  6545.  
  6546.                 lda        |m_blk_cnt+2
  6547.                 and        #$007f
  6548.                 rol        a
  6549.                 ora        |m_rslt+3            ;Watch out for that +4 value.
  6550.                 sta        |m_rslt+3            ;It doesn't belong to us.
  6551.  
  6552.                 jmp        @clean
  6553.  
  6554.                 ENDIF
  6555.  
  6556. ;-------------------------------------------------------------------------------
  6557.  
  6558.                 IF            scsi_dtype = apple_cd    THEN
  6559.                                             ;
  6560.                                             ; Quick Multiply by $0200
  6561.                                             ;
  6562.                 lda        |m_blk_cnt
  6563.                 asl        a
  6564.                 sta        |m_rslt+1
  6565.  
  6566.                 lda        |m_blk_cnt+2
  6567.                 and        #$007f
  6568.                 rol        a
  6569.                 ora        |m_rslt+3            ;Watch out for that +4 value.
  6570.                 sta        |m_rslt+3            ;It doesn't belong to us.
  6571.  
  6572.                 jmp        @clean
  6573.  
  6574.                 ENDIF
  6575.  
  6576. ;-------------------------------------------------------------------------------
  6577.  
  6578. @not_512
  6579.                                             ;
  6580.                                             ; Actual Multiply Loop.
  6581.                                             ;
  6582.                 lsr        |m_blk_size
  6583.                 bcc        @shift_cnt            ;Don't Add this one.
  6584.                                             ;
  6585.                                             ; Add in Current Byte Count.
  6586.                 clc
  6587.                 lda        |m_rslt
  6588.                 adc        |m_blk_cnt
  6589.                 sta        |m_rslt
  6590.                 lda        |m_rslt+2
  6591.                 adc        |m_blk_cnt+2
  6592.                 sta        |m_rslt+2
  6593.                                             ;
  6594.                                             ; Multiply Count by 2.
  6595.                                             ;
  6596. @shift_cnt        asl        |m_blk_cnt
  6597.                 rol        |m_blk_cnt+2
  6598.  
  6599.                 lda        |m_blk_size
  6600.                 bne        @not_512            ;only do till 0  ( <16 times )
  6601.                                             ;
  6602.                                             ; Clean Exit.
  6603.                                             ;
  6604. @clean            clc
  6605.                 rts
  6606.  
  6607.                 ELSE
  6608.  
  6609. ;-------------------------------------------------------------------------------
  6610.  
  6611.                 lda        #null
  6612.                 clc
  6613.                 rts
  6614.  
  6615.                 ENDIF
  6616.  
  6617. ;-------------------------------------------------------------------------------
  6618.  
  6619.                 ENDP
  6620.  
  6621.                 EJECT
  6622.  
  6623.                 END